【问题标题】:Selenium is showing element not found exceptionSelenium 显示未找到元素异常
【发布时间】:2013-12-24 19:49:42
【问题描述】:

我可以使用 selenium 在第一页上进行验证。但是当我转移到下一页时,它会显示上述错误。

代码是:-

WebDriver driver = new FirefoxDriver();

        String baseUrl = "http://192.168.1.47";
        Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
        driver.get(baseUrl);
        selenium.open("http://192.168.1.47");
       selenium.type("username","clnt123822");
        selenium.type("birthday", "150347");
        String name = driver.findElement(By.name("username")).getAttribute("value").toString();
        String dob = driver.findElement(By.name("birthday")).getAttribute("value").toString();
        System.out.println(name);
        System.out.println(dob);
        selenium.click("btnsubmit");
   // After pressing this button it is going to next page where i am having select
html tag.At this point error is coming  

线程“main”com.thoughtworks.selenium.SeleniumException 中的异常:未找到元素 select1

这是第二页检查,它会抛出错误

selenium.type("select1","r");

            String select1 = driver.findElement(By.id("sel1")).getAttribute("value").toString();

            System.out.println(select1);

【问题讨论】:

  • 我的水晶球告诉我这是因为它找不到元素... ;-) 请提供有关相关页面的更多详细信息(最好是 html 块)否则我们不会能够帮助你。
  • 您正在使用 both WebDriver 和 WebDriverBackedSelenium。这不会有帮助。放下其中一个。

标签: selenium selenium-webdriver


【解决方案1】:

我想您需要等到第二页中的元素可见/可点击。在点击第一页中的提交按钮后尝试此代码。

WebElement element = new WebDriverWait(Driver,30).until(ExpectedConditions.elementToBeClickable(By.id("sel1")));

【讨论】:

  • 感谢您的建议,但我已使用以下代码解决了问题
  • driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
猜你喜欢
  • 2018-05-20
  • 2020-11-11
  • 2014-05-24
  • 1970-01-01
  • 2022-06-23
  • 1970-01-01
  • 1970-01-01
  • 2020-10-21
  • 1970-01-01
相关资源
最近更新 更多