0

I Have a selenium bot I'm working on that works fine. But I can't find the accurate syntax I shall use to grep the body element. To reach an element I generally just use something like this:

canvas = driver.find_element("id", "canvas")

But for the body element, no one of the regular syntax works. I've tried:

find element_by("tagName", "body")
find element_by(by="tagName", value="body")

and different versions of tag_name, tagName, and so forth. I Can't use the By. since I have not imported it yet, which is a piece of cake anyway, but should it be necessary and would that help?

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24

1 Answers1

0

i suggest to use xpath find_element_by_xpath() as it is well known and comparably easy to use.

For a first introduction have a look at:

W3-Schools_xpath_tutorial

For identifiying the HTML elements see:

octoparse_locate_xpath

And for you future xpath´s there is this cool cheatsheet:

devhints_xpath

Knight
  • 205
  • 1
  • 9
  • Thx!, saw it worked with the By class to - but prefer not importing more than i need (: This suits me mutch better. – William Knutsson May 16 '23 at 14:48
  • Thats fine it takes a while to get used to xpath. Note: to use xpath with selenium webdriver there are no extra imports neccessary and it is also possible to use the class attribute in combination with xpath. – Knight May 17 '23 at 05:47