2

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

asked Jul 29, 2017 at 21:59

1 Answer 1

1

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")
answered Jul 29, 2017 at 22:35
Sign up to request clarification or add additional context in comments.

1 Comment

wow thanks that totally worked. i wasn't expecting an answer this quick

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.