What happens is that I have this webpage: The following
div
is what's visible in cyan in the screenshot above. I've circled the bit of text I'm trying to find:
I've tried Xpath and CSS. They both work in Firebug and they both locate the elements fine inside this floating div. But when I run my script, I get the nosuchelement exception.
-Things I'm suspicious of:
I don't think it's necessary, but here is one of the CSS locators that I'm using in Firepath and works in locating the 5040 text.
driver.findElement(By.cssSelector(".feature>tbody>tr>td[width='312']")
So the question here is: how do I locate this text in these td
's if my xpath/css locators work manually but not with WebDriver?
See that iframe
element - it is the reason you are getting the exception.
You need to switch to iframe
before finding an element:
driver.switchTo().frame("Content")
Or (in case it is not working due to spaces in the id
):
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[id$=Content]"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.