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


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?
Who is Participating?
Craig KehlerDirector of Customer Service & Community RelationsCommented:
Get the Selenium IDE addon for firefox. You can record actions in the browser and even format the copy buffer to your desired language.
Direct download link

Once you have the IDE open, select Options-> Clipboard format and select your desired language. Now if you select a recorded action and copy it, you can paste the code directly.

Also note that once you've recorded something you can select a particular action, then select the drop down to the far right of Target and you can choose which locator you want.

You can also prioritize locators in Options->Options->Locator Builders
Dave BaldwinFixer of ProblemsCommented:
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.
Craig KehlerDirector of Customer Service & Community RelationsCommented:
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.
IzzyTwinklyAuthor Commented:
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:
Craig KehlerDirector of Customer Service & Community RelationsCommented:
Have you tried the firefox driver?
The status of this bug is won't fix.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.