Home Ask Login Register

Developers Planet

Your answer is one click away!

Harshul Sahni February 2016

Turn Array of Selenium Webdriver Elements into their values?

I was trying to scrape this website, which has a table. One of the rows contained the info i needed (Let's just say each cell looked like one of these entries: [12%, 34%, 27%, 38%])

I selected all of these percentages by using this line:

notes = driver.find_elements_by_xpath("//*[contains(text(),'%')]").text

There was no better was to do this; there were no class names or id names for me to select

After I printed this array, it gave me this input: Element Array Input

I'm assuming these are the elements of the percentages, but how do I convert this array to print out the array with the actual percentages (ex. [12%, 34%, 27%, 38%])?



dm295 February 2016

find_elements_by_xpath (all selenium find_elements... methods returns a list) returns a Python list, you have to call .text on list items, not the list itself.

notes = driver.find_elements_by_xpath("//*[contains(text(),'%')]")
notes = [note.text for note in notes]

Post Status

Asked in February 2016
Viewed 3,736 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life