0
votes

When recorded in Selenium IDE, the result is this:

click //span[@id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/hd/font/span/acronym

Here is my entry in Eclipse using WebDriver(Java)

driver.findElement(By.xpath("//span[@id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/h2/font/span/acronym")).click();

Here is the error I receive:

no such element: Unable to locate element: {"method":"xpath","selector":"//span[@id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/h2/font/span/acronym"},

HTML

<span onclick="change_site"('SITES');" style="cursor:pointer; color:#12345; text-decoration:underline;">
    <acronym title=Site ID:">DEFAULTSITE</acronym>
</span>
4
<b> This is how the HTML code looks when I inspect the element with FireBug: "<span onclick="change_site"('SITES');" style="cursor:pointer; color:#12345; text-decoration:underline;"><acronym title=Site ID:">DEFAULTSITE</acronym></span>" I want to click on the "DEFAULTSITE" link - javapyt
Thanks for all your responses below. They all seem logical and I don't see why they won't work, but I keep getting the same error. I have tried all the suggestions below. Please let me know if there is any other information that may be helpful. Is there anything I can provide or do from the Selenium IDE that may be helpful? Thanks! - javapyt
Okay I figured it out. I basically had to switch to the appropriate frame first . I used this statement: driver.swithTo().frame("frame name"), then I clicked on a link using the By.cssSelector. This solved my problem! - javapyt

4 Answers

1
votes

As per the HTML provided you can directly access the acronym element

driver.findElement(By.xpath("//span/acronym[@title='Site Id:']")).click();
0
votes

Try with below xPath :

driver.findElement(By.xpath("//acronym[contains(text(),'DEFAULTSITE')]").click();
0
votes

Try any of the below xpath

driver.findElement(By.xpath("//acronym[text()='DEFAULTSITE']");
driver.findElement(By.xpath("//span/acronym[text()='DEFAULTSITE']");

Or this css

driver.findElement(By.css("acronym[title='Site']");
0
votes

If none of the above Xpath has worked for you ,please try the following Xpath

//span[@id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/hd/font/span/*[name()=acronym]

Please let me know if this has helped you or not.