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));
  • <a href=www.google.com/url?url=www.xyz.com/> www.xyz.com/1213sdsd/en-us <a> Commented Feb 26, 2020 at 9:52
  • what is the issue with this ? whats the error you getting
    – PDHide
    Commented Feb 26, 2020 at 9:57
  • Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"partial link text","selector" Commented Feb 26, 2020 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
    Commented Feb 26, 2020 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. Commented Feb 26, 2020 at 10:09


Browse other questions tagged or ask your own question.