New to Java and Selenium, I'm facing difficulties when trying to click on a link with JavaScript in href attribute. Here's the snippet from the page source:
href="javascript:navigateToDiffTab('https://site_url/medications','Are you sure you want to leave this page without saving your changes?');" tabindex="-1">Medications
For privacy reasons, I've replaced the actual URL with "site_url."
I attempted to use the following code, but it didn't work as expected:
driver.findElement(By.cssSelector("a[href^='javascript:navigateToDiffTab'][href$='site_url/medications']")).click();
I prefer not to rely on id or linkText due to environmental and language differences.
If anyone could offer some assistance, it would be greatly appreciated.