【问题标题】:Unable to click on dropdown list option after list is displayed automatically for NetSuiteNetSuite 自动显示列表后无法单击下拉列表选项
【发布时间】:2021-11-26 11:08:32
【问题描述】:

我试图简单地单击输入单词 Advance 后显示的下拉列表。但是我不断收到错误消息。线程“主”org.openqa.selenium.NoSuchElementException 中的异常:没有这样的元素:无法找到元素:

 public void supplier (WebDriver driver)
    {
        Actions action = new Actions(driver);
        WebElement supplierLink = driver.findElement(By.id("_searchstring"));
        supplierLink.sendKeys("Advance");
        
        //*[@id="/app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108"]
        //WebDriverWait wait = new WebDriverWait(driver, 5); 
        //wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108")));
        
        WebElement clickadvance = driver.findElement(By.id("/app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108"));
        action.moveToElement(clickadvance).perform();
        
    }

【问题讨论】:

  • 您想从填充选项中选择哪个选项?
  • 我正在尝试选择 - 页面:前进
  • 您能以文本格式共享相同的 HTML。转到 HTML 中的该选项,然后右键单击并选择外部 HTML。

标签: java selenium automation


【解决方案1】:

请在您的代码中添加等待条件,这将起作用,

WebDriverWait wait = new WebDriverWait(driver, 20);
By optionXpath = By.id("/app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108");
wait.until(ExpectedConditions.elementToBeClickable(optionXpath));
driver.findElement(optionXpath).click();

如果不是您的 xpath 错误,请相应地更改 xpath。

【讨论】:

    【解决方案2】:

    请使用这个 xpath

    //span[text()='Advance']/parent::a[@role='option' and contains(@id,'/app/accounting/transactions/transactionlist.nl?')]
    

    请确保它应该代表正确的元素。

    代码试用 1:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Advance']/parent::a[@role='option' and contains(@id,'/app/accounting/transactions/transactionlist.nl?')]"))).click();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      相关资源
      最近更新 更多