1

Have to inspect element 8. When click the element 8 on webpage.It should redirects to next page

<td class="text_overflow-1">
<u>
<a targrt="_parent();" href="subscriberall.php?key=138">8</a>
</u>
</td>

I have tried the following locators

  //a[@href="subscriberall.php?key=138"]
  driver.findElement(By.linkText("8")).click();

When run the above code in selenium webdriver. What actually happened means, it inspects element 8. But it doesnot clickable to next page

5
  • What do you mean it doesnot clickable to next page? Do you want to jump to next page? Commented Dec 26, 2015 at 12:19
  • Yes want to jumb to next page. But its not function, when tried the above locators
    – josh test
    Commented Dec 26, 2015 at 12:38
  • Next page- is it in same tab or other- or any other window? Commented Dec 26, 2015 at 12:45
  • When click 8, it redirects to same tab.
    – josh test
    Commented Dec 26, 2015 at 13:33
  • Bit late, but which browser? I have some versions of Internet Explorer seen to not register the first click correctly, this was because of the wrong focus. Clicking twice could help here :) Commented Sep 6, 2016 at 7:28

3 Answers 3

1

NOTE: You should ask your developers to put in a unique id in the page element so that it will be reusable. The attributes you have now will not suffice.

Usually an element is not clickable if you don't associate your page object to the a tag. So, when your developer adds a unique id into the a tag (let's say id = unique) then this should work.

driver.findElement(By.cssSelector("u a[id='unique']")).click();
1
//a[@href="subscriberall.php?key=138"]
driver.findElement(By.linkText("8")).click();

There could be a variety of reasons why the above locators do not work. I also noticed a typo in

<a targrt="_parent();"...

It would be very advantageous to check your error log from the IDE/Terminal and copy/paste them so we can get a better idea of what specific issue you are having with the locators. If the element cannot be found that could mean the xpath query you wrote above has a dynamic key=XXX which is very brittle. In this case you may want to change it to

//u/a[contains(@href, 'subscriberall.php?key=')]
1

You can try following xpath

//div[@class='text_overflow-1']/u/a

driver.findElement(By.xpath("//div[@class='text_overflow-1']/u/a")).click();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.