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
Post a Comment