How to handle Javascript click by using selenium Webdriver? -


am using selenium webdiver. test-case is.

  1. login site.
  2. click on notifications link.

am facing issue while clicking on notification link, having html code follows :-

<ul class="rghtsec fr menu logged"><li><a href="javascript:;">   <div class="topicon notify"><span>&nbsp;</span></div>   <div class="mtxt">notifications<span id="rjobcntr" class="rjobcntr"></span></div></a>   <div class="submenu recommendtt">     <ul>       <li><a target="_blank" class="blob" id="blobid" href="http://jobsearch.naukri.com/notifications"> fetching jobs may apply for</a></li>     </ul> 

i have tried following 5 different ways:

/*1*/ driver.findelement(by.xpath("//a[@class='mtxt']")).click();  /*2*/ driver.findelement(by.cssselector("div[class='topicon notify']")).click();  /*3*/ driver.findelement(by.linktext("notifications")).click();  /*4*/ driver.findelement(by.xpath("//div[@class='pnotifycont dspn']")).click();  /*5*/ actions mouse=new actions(driver);    webelement element=driver.findelement(by.xpath("//div[@class='pnotifycont dspn']"));    mouse.movetoelement(element).click().build().perform(); 

error : exception in thread "main" org.openqa.selenium.nosuchelementexception: unable locate element: {"method":"xpath","selector":"//a[@class='mtxt']"} command duration or timeout: 7.56 seconds

but none of these ways resolving problem :(, can please me solve this?

you can directly click on link based on value of href attribute:

driver.findelement(by.cssselector("a[href*='notifications']")).click(); 

or

driver.findelement(by.cssselector("a[href=\"http://jobsearch.naukri.com/notifications\"]")).click(); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -