首页 > 解决方案 > NetSuite 自动显示列表后无法单击下拉列表选项

问题描述

我试图简单地单击输入单词 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();
        
    }

在此处输入图像描述

标签: javaseleniumautomation

解决方案


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

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。


推荐阅读