Reputation: 1
I am getting NoSuchElementException
for an element and because of which my regression suite is failing. I have used XPATH, CSS selector and when searched in Chrome using those locators, I am able to find the element.
Till now I have used:
Thread.sleep(<milliseconds>)
Implicit Wait
Explicit/Fluent
Wait using .visibilityOf(WebElement)
and .prescenceOfElementLocatedBy(locator)
Even I have used Absolute XPath but no success. Please suggest what I can do to make it work. I need to capture the text content of h1 tag and then apply switch case based on the value captured, to perform further function. But my scripts are failing in locating h1.headline locator, however I can easily locate it in Chrome manually. Below is my code:
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("h1.headline")));
String BDName = driver.findElement(By.cssSelector("h1.headline")).getAttribute("innerHTML");
System.out.println(BDName);
BDName = BDName.trim();
switch (BDName) {
case "Authenticate Your Identity": {
this.fnesignForConsumerFlow(qry);
break;
}
case "Welcome to eQuipt!": {
try {
String strSubTitle = this.driver.findElement(By.xpath("//h2[@class='sub-headline']"))
.getAttribute("innerHTML");
if (strSubTitle.contains("Let's Get Started by Creating Your Username and Password")) {
webmaileSign.fnEQuiptSignUp(qry);
this.fnesignForConsumerFlow(qry);
} else {
this.fnesignWithOTP(qry);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;
}
Below is the DOM structure:
Upvotes: 0
Views: 47