我有一个基类,我在其中定义了webDriver(使用Guice)。这我beforeclass与下面的代码行沿定义没有这样的元素:无法定位元素:来自webdriver的异常
@Inject
protected Provider<WebDriver> webDriverProvider;
protected static WebDriver webDriver;
我有这被beforesuite后执行另一个类,它有,我已经写了我的测试对于一个给定功能的方法1。它看起来是这样的
public void method1() throws InterruptedException {
Thread.sleep(3000);
log.info("Navigating to Method1");
webDriver.findElement(By.xpath(Element1)).click();
}
这里的问题是,当行
webDriver.findElement(By.xpath(部件1))点击()。
执行我得到一个异常消息org.openqa.selenium.NoSuchElementException:没有这样的元素:找不到元素:
XPath是正确的。我这个方法是我beforesuite的部分之前已经对话框
我尝试添加点击上面的语句下面几行:
webDriver.switchTo().defaultContent();
log.info(webDriver.findElement(By.xpath(部件1) ).getAttribute(元素1)); webDriver.findElement(By.xpath(Element1))。isDisplayed();
的问题是第一个实例,其中“webdriver的”位于它抛出一个异常NoSuchElementException异常
任何指针将帮助我进一步调试它。
感谢。
我在Class2中 – Prabhath
扩展的Class1按照这个答案http://stackoverflow.com/questions/39190910/nosuchelementexception-unable-to-locate-元素/ 39191349#39191349 –
Saurabh:它不在iframe中,而且我已经实现了等待10秒钟,但没有解决问题。 – Prabhath