I've a base class where in I've defined webDriver as (using Guice). This has my beforeclass defined along with the below line of code
@Inject
protected Provider<WebDriver> webDriverProvider;
protected static WebDriver webDriver;
I've another class which gets executed after beforesuite and it has a method1 where I've written my test for a given function. And it looks something like this
public void method1() throws InterruptedException {
Thread.sleep(3000);
log.info("Navigating to Method1");
webDriver.findElement(By.xpath(Element1)).click();
}
The problem here is when the line
webDriver.findElement(By.xpath(Element1)).click();
is executed I get an exception message as org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
Xpath is correct. I've a dialog box before this method which is part of my beforesuite
I tried adding following lines above the click statement:
webDriver.switchTo().defaultContent();
log.info(webDriver.findElement(By.xpath(Element1)).getAttribute(Element1)); webDriver.findElement(By.xpath(Element1)).isDisplayed();
The problem is the first instance where "webDriver" is located it throws an exception as NoSuchElementException
Any pointers would help me in debugging it further.
Thanks.