J_Coder
J_Coder

Reputation: 737

Mouse Hover Action-Unable to click hidden Link

I am unable to click hidden link("WatchBanking") after using move-to-element.

WebElement lnkW2yB=dr.findElement(By.xpath("//a[@href='/personal/ways_to_bank/ways-to-bank-landing']"));
    Actions act=new Actions(dr);
    act.moveToElement(lnkW2yB).build().perform();
    WebElement Span=dr.findElement(By.xpath("//span[contains(text(),'Bank with your Watch')]"));
    WebDriverWait wait=new WebDriverWait(dr,20);
    wait.until(ExpectedConditions.visibilityOf(Span));
    act.moveToElement(Span).build().perform();
    Thread.sleep(5000L);
    WebElement lnk=dr.findElement(By.linkText("WatchBanking"));
    wait.until(ExpectedConditions.visibilityOf(lnk));
    act.moveToElement(lnk).click(lnk).build().perform();

It Moves to the span("Bank with your Watch") and shows link("WatchBanking"). But its not clicking on WatchBanking due to immediate disappearance. Please give me any solution on this.

Upvotes: 0

Views: 150

Answers (1)

Madhan
Madhan

Reputation: 5818

Selenium sometimes behaves like that only.I would go with JavascriptExecutor at times like this.I've repaced Selenium click by Javascript click and it worked perfectly for that site you've mentioned in comment.

Replace the lnk.click() by the following

 WebElement lnk = dr.findElement(By.xpath("//a[text()='WatchBanking']"));
    wait.until(ExpectedConditions.visibilityOf(lnk));
    JavascriptExecutor js = (JavascriptExecutor) dr;
    js.executeScript("arguments[0].click();", lnk);

Upvotes: 1

Related Questions