html - Get page element by title attribute - Selenium and Java -
i'm trying image has word "collector" in title , click on it. html code image , link:
<a href="javascript:*command*" title="level iii: kpi collector ryg of d d/testing - sys"> <img src="*unusable link because it's valid specific page*" title="level iii: kpi collector ryg of d d/testing - sys"> the <a> , <img> tags nested in table cell , divs. didn't write html code don't yell @ me if it's ugly :p
here java code try it:
webelement trafficlight = driver.findelement(by.xpath("//img[contains(@title,'collector')]")); trafficlight.click(); the error is:
exception in thread "main" org.openqa.selenium.nosuchelementexception: unable locate element: {"method":"xpath","selector":"//img[contains(@title,'collector')]"} i'm pretty sure xpath ok don't think that's issue.
as img webelement within frame, need switch focus frame before perform action on webelement. can using webdriver's switchto() method so:
driver.switchto().frame(framelocator); the frame locator can either (zero-based) index, name or id attribute, or located webelement.
once have switched focus required frame, should able interact webelement using same code in initial post.
Comments
Post a Comment