java - selenium click link href with javascript -


i newbie java , selenium. having issue in clicking link javascript in href. below page source:

href="javascript:navigatetodifftab('https://site_url/medications','are sure want leave page without saving changes?');" tabindex="-1">medications 

please note: replaced actual url "site_url" because of business concerns.

i tried below code did not work:

driver.findelement(by.cssselector("a[href^='javascript:navigatetodifftab'][href$='site_url/medications']")).click(); 

i not want use id or linktext changes different environments , languages.

any appreciated.

use below code. working fine me:-

webelement element= driver.findelement(by.cssselector("a[href^='javascript:navigatetodifftab'][href$='site_url/medications']"))  javascriptexecutor executor = (javascriptexecutor) driver; executor.executescript("arguments[0].click();", element); 

if above code not work means there problem locator. try other locator or post html code in question can identify exact locator you.

hope :)


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -