Foot-OM

How to click the <a> tag in selenium

Below is my code. Paste the entire tag

<TR id="oldcontent" bgcolor="#D0D0D0"> <TD id="oldcontent">Foot-OM</TD> <a id="oldcontent" href="ID=22143"><u>Re-Submit</u></a> <a id="oldcontent" href="ID=22143"><u>View</u></a> <TR> 

Here I need to click the tag using the re-send text. The problem is href = "ID = 22143", the id value is generated dynamically every time I run a test case. Therefore, I need to click the Re-submit tag, using the text present in the first text, i.e. Foot-OM.Can, someone will provide me with xpath>

+4
source share
4 answers

You can click on it as follows:

 selenium.click("//a/u[contains(text(),'Re-Submit')]"); 

For Webdriver:

 driver.findElement(By.xpath("//a/u[contains(text(),'Re-Submit')]")).click(); 
+6
source

In ruby ​​Selenium webdriver

 @driver.find_element(:link, "Re-Submit" ).click 

using selenium RC perl

 $sel->click("link=Re-Submit"); 
+2
source

It looks like your problem is with the wrong HTML structure. The <a> tag cannot be placed in <tr> . Only <td> is allowed. The browser "fixes" errors, and <a> tags are displayed outside the table, and the DOM structure does not coincide with html.

Fixed DOM by Browser

This XPath works for the image above.

 //td[text()='Foot-OM']/../../../../a[//text()='Re-Submit'] 
0
source

U can just write 1.selenium.click ("link = Re-Submit") and 2.selenium.click ("link-View").

0
source

All Articles