0

suppose the following is mentioned in the tag a:

<a href=www.google.com/url?url=www.xyz.com> www.xyz.com/1213sdsd/en-us </a> 

The text between the tagname is also a link. How do I select the same using driver object in selenium.

my code:

String link = "www.xyz.com";
WebElement link = driver.findElement(By.partialLinkText(link));
link.click();
12
  • <a href=www.google.com/url?url=www.xyz.com/> www.xyz.com/1213sdsd/en-us <a> – Selenium Novice Feb 26 '20 at 9:52
  • what is the issue with this ? whats the error you getting – PDHide Feb 26 '20 at 9:57
  • Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"partial link text","selector" – Selenium Novice Feb 26 '20 at 10:03
  • try using explicit wait, to make sure the element is present. also try this locator driver.findElement(By.css(a[href*="www.google.com"])) – PDHide Feb 26 '20 at 10:08
  • I am trying to click the text www.xyz.com/1213sdsd/en-us using partial link but it ends up in an exception. Usual text is working fine, if i have something like <a href = "www.google.com"> Google </a>.and i use by.linkText("Google").click(); Not able to use the same logic for the link in the tag. – Selenium Novice Feb 26 '20 at 10:09