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?
IzzyTwinklyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
0
Craig KehlerDirector of Customer 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.
http://www.seleniumhq.org/download/
Direct download link http://release.seleniumhq.org/selenium-ide/2.9.0/selenium-ide-2.9.0.xpi

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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Craig KehlerDirector of Customer 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.
0
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:
driver1.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver1.FindElement(By.XPath("(//a[contains(text(),'Images')])[2]")).Click();
0
Craig KehlerDirector of Customer RelationsCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.