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

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -