我有一個基類,我在其中定義了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