Reputation: 1
Problem is I want to locate many elements which share same css path but when I use
elements= webdriver.find_elements_by_css_selector("")
This only works if I open inspect element.
However when running the code without opening inspect element I got
elements=[ ]
"nothing found"
I use css path because it's the only Mutual thing between the elements I want to locate.
Upvotes: 0
Views: 1056
Reputation: 2814
as i have tested, the css path is the "full" path trough the DOM tree to the element you wish to locate. Starting from html tag to (n) item.
That include each element in the tree until you reach the focused element. Example:
html.wf-nunitosans-n4-active.wf-active body#gsr.hp.vasq.big div#viewport.ctr-p div#searchform.jhp.big form#tsf.tsf.nj div div.A8SBwf div.FPdoLc.tfB0Bf center input.gNO89b
CSS selector is the shortest path using css locators and axes to the focused item.
Example:
.FPdoLc > center:nth-child(1) > input:nth-child(1)
Hope this helps you.
Upvotes: 2