Xpath and CSS selector of objects whose ids changing | Selenium Forum
M
Posted on 27/11/2015
Hi Ashish,

I am done with video 4 of module 12 here you have given awesome explanation of X path and CSS selector of objects whose ids dynamically changing in a webpage.But I am stuck during finding X path and CSS selector for "games.com" as suggestion string displayed in yahoo page when user enters games in input box.(Similar example as you explained in mentioned video). Kindly refer below attached snapshot.

Please look into this and explain how can I find X path and CSS selector for the same.

Thanks a lot in advance.

M
Replied on 27/11/2015

to tell you the truth dynamic elements are hard automate. especially very hard on yahoo.


M
Replied on 28/11/2015

so is it no way to automate this? Responsive image


M
Replied on 29/11/2015

there are ways to handle dynamic elements.

watch module 17th where we extract names of facebook friends. that will give you an idea how to go about it.


M
Replied on 02/12/2015

okay. Thanks a lot.


M
Replied on 08/12/2015

[attachment=2:1e95f0xr]Facebook Page.png[/attachment:1e95f0xr]Hi Ashish,

I am automating facebook page there is a text field "Create an account". Its X path is "//*[@id='content']/div/div[1]/div/div/div[2]/div[1]/div[1]/span ". Instead of X path I am using CSS selector and written CSS selector as "div[id='content'] div div[1] div div div[2] div[1] div[1] span" but its not working. In console, I am getting error of given selector is either invalid or does not result in a Web element.While if I write CSS selector as "div[class='mbs _52lq fsl fwb fcb'] span"(just above span tag I have used div tag which contains class attribute) for the same web element its working fine. So could you suggest me where I am wrong I want to write CSS selector which contains id attribute.please refer snapshot attached.

Thanks in advance.

Responsive image

M
Replied on 09/12/2015

[quote:ilv1wvsx]"div[id='content'] div div[1] div div div[2] div[1] div[1] span"[/quote:ilv1wvsx]

it will not work. because facebook has dynamic elements. so this css path will not work.