Link to home
Start Free TrialLog in
Avatar of IzzyTwinkly
IzzyTwinklyFlag for United States of America

asked on

How would you locate an object in the Chrome web browser for Selenium?

Hi,

I am trying to click "Images" link in Google page.
The browser I am using is Chrome. you go to Google and enter something on the searchbox, then all the links are appeared.  I was successful up to this point. After this, I right clicked my mouse on Image hyperlink on Google and selected "Inspect element' option. There was no 'id' for Images hyperlink
Some of codes I used for this were
var imageLink =  driver1.FindElement(By.XPath(@"//*[@id=""hdtb_msb""]/div[3]/a"));
var imageLink =  driver1.FindElements(By.ClassName("q_qs"))[2];
I also used LinkText and TagName, but the exceptions were returned.

I am using C# in Visual Studio 2013 ultimate version.
Can anybody help me with this?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

This is what the content of an image tag in a Google Images page looks like.  There is no 'id' attribute.  Note that the image data is embedded in the page in the 'src' attribute.  At this point, it is not in a separate file.

<img class="rg_i" jsaction="load:str.tbn" alt="Image result for blue whale" name="uRjOKyzWwdibPM:" data-sz="f" style="width:300px;height:168px;margin-left:0px;margin-right:0px;margin-top:0px" src="data:image/jpeg;base64,/9j/4AA…nVu6PZK3My6NEBDm6r6604/b//2Q=="></img>

Open in new window

You might want to pick an easier site than Google Images to develop your code and come back to this later.
ASKER CERTIFIED SOLUTION
Avatar of Craig Kehler
Craig Kehler
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also I agree with what Dave said, google isn't the easiest site to automate and they also don't appreciate automation of their site. They will flag and redirect people they catch sending automated requests.
Avatar of IzzyTwinkly

ASKER

Thanks Craig, I already tried Selenium IDE, and used the same code to click "Images" link. However, I got "InvalidOperaionException" error.  error msg. says "unknown error: Element is not clickable at point (352, 89). Other element would receive the click: <div class="sbqs_c">...</div>
  (Session info: chrome=41.0.2272.89)
  (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86_64)"

I used the following code:
driver1.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver1.FindElement(By.XPath("(//a[contains(text(),'Images')])[2]")).Click();
Have you tried the firefox driver?
The status of this bug is won't fix. https://code.google.com/p/selenium/issues/detail?id=2766