jan deeg
jan deeg

Reputation: 41

python selenium xpath horror

i know i am doing something wrong here but i would like your help on this one

i have this html code

<span id='some text'>some text</span>  
<ul> this is what I would like to grab </ul>
<span id='some more text'>some more text</span>

so i tried something and since this is the first time i am working with xpath i was quite sure i was doing wrong.

driver.find_elements_by_xpath('//ul[preceding:://span[@id="some text"] and  following:://span[@id="some more text"] ')

any help is appreciated

Upvotes: 2

Views: 65

Answers (1)

Florent B.
Florent B.

Reputation: 42538

An id attribute is supposed to be unique, so one is enough to select a branch.

To get the <ul> tag following the <span id='some text'>:

driver.find_elements_by_xpath("//span[@id='some text']/following-sibling::ul[1]")

, and with a CSS selector:

driver.find_elements_by_css_selector("span[id='some text'] + ul")

Upvotes: 1

Related Questions