I am using a python3.x script to save a string to a text file:
nN = "hello"
f = open("file.txt", "w")
f.write(nN)
f.close()
and now I am trying to parse the content of an h2 element from a website (page scraping works fine) and I am getting an error when I am trying this:
nN = driver.find_element_by_id("title")
f = open("file.txt", "w")
f.write(nN)
f.close()
where the html line is:
<h2 id="title">hello</h2>
The error is:
write() argument must be str, not WebElement
I tried converting the nN into a string using the following:
f.write(str(nN))
and the new error is:
invalid syntax
f.write(str(nN))? I'm not sure what adriverobject is, or whatfind_element_by_id()returns; but as the error states,f.write()must have a typestras its explicit parameter.