1

I am trying to parse the wind direction using selenium and I think using xpath is the easiest way to get this info. There is a table with all the information and the xpath of the elements within this table follow the same structure, hence my following code:

wind_directions = [browser.find_element_by_xpath(f'//*[@id="archive_results"]/table/tbody/tr/td/table/tbody/tr[3]/td[{i}]').text for i in range(14,25)]

Indeed, the structure of the data on the site is the following: Data structure in the table

My issue is that I would like to get the content "rotate(494, 50, 50) translate(0,5)" from the picture above but I can't: If I try to write replace the previous fstring with f'//*[@id="archive_results"]/table/tbody/tr/td/table/tbody/tr[3]/td[{i}]/svg/g'], The compiler tells me that Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="archive_results"]/table/tbody/tr/td/table/tbody/tr[3]/td[14]/svg/g"}.

Any idea why I get such a message while this is the exact xpath that appears when I check on the element on Chrome ? (I triple-checked the indexes in the fstring and it is not the source of the error).

1 Answer 1

1

svg g etc. are special tag names.
To locate such nodes with XPath you can change your XPath expression as following:

'//*[@id="archive_results"]/table/tbody/tr/td/table/tbody/tr[3]/td[{i}]/*[name()="svg"]/*[name()="g"]'
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.