Issue
The submenus are getting appeared in the DOM only when we hover over the main menu. So after hovering over main menu using Actions class the submenus are coming, but then again when I am trying to get into the submenu it is getting detached from the DOM. Please help me on this.
public void goToMenTopWearSectionFromFashion() throws InterruptedException
{
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Actions act=new Actions(driver);
try {
act.moveToElement(FashionHeaderLink).perform();
}
catch(Exception e)
{
act.moveToElement(driver.findElement(By.xpath("//div[@class='_1psGvi SLyWEo']//div[text()='Fashion']"))).perform();
}
try {
if(driver.findElement(By.xpath("//*[@class='_3XS_gI _7qr1OC']//a[1]")).isDisplayed())
{
System.out.println(driver.findElement(By.xpath("//*[@class='_3XS_gI _7qr1OC']//a[1]")).isDisplayed());
driver.findElement(By.xpath("//*[@class='_3XS_gI _7qr1OC']//a[1]")).click();
}
}catch(Exception e) {e.printStackTrace();}
}
Solution
After the hover, trying to move to click on Men's Top Wear was sometimes causing it to disappear along the way. I experienced the same by hand if I moved diagonally rather than straight down. Instead,in your 2nd try block you can do the following:
if(driver.findElement(By.linkText("Men's Top Wear")).isDisplayed())
{
String urlSave = driver.findElement(By.linkText("Men's Top Wear")).getAttribute("href");
driver.get(urlSave);
}
Probably it would work with your locator, too.
Answered By - Jeremy Kahan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.