0

When using find_element_by_xpath it will return a str of all text inside that xpath. The output returns a str but I would need to convert this into a list. Or just return "1 bed room".

selenium xpath

result = driver.find_element_by_xpath('//*[@id="summary"]/following-sibling::*[1]').text

OUTPUT

2 guests
1 bedroom
1 bed
1.5 baths

Desired output

[2 guests,1 bedroom,1 bed,1.5 baths]
1
  • Split on the newline character. Commented Sep 17, 2019 at 17:10

1 Answer 1

1

Splitting by newline should give you what you want.

result = driver.find_element_by_xpath('//*[@id="summary"]/following-sibling::*[1]').text
result.splitlines()

Unless there are other elements under the element your xpath returns this is the best you can do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.