I am new in selenium. What I want to do is to execute javascript function through python. And use the value returned by javascript function. I am stuck with above error. Please help me. This is my js code:
var doc = ""
var p = document.getElementsByTagName("p")
var s = p[0].parentElement
for (var i=0; i<s.childElementCount;i++)
{
var a = s.children[i]
scrap(a)
}
result()
function scrap(a)
{
if (a.tagName == "H1")
doc = doc +a.innerText
else if (a.tagName == "H2") {
doc = doc +a.innerText
}
else if (a.tagName == "H2") {
doc = doc +a.innerText
}
else if (a.tagName == "H3") {
doc = doc +a.innerText
}
else if (a.tagName == "H4") {
doc = doc +a.innerText
}
else if (a.tagName == "P") {
var j = a.childElementCount
doc = doc +a.innerText
}
else if (a.tagName == "img") {
doc = doc +a.innerText
}
else if (a.tagName == "li") {
doc = doc +a.innerText
}
doc = doc + "\n"
}
function result()
{
return "doc"
}
And this the python script:
js = open("generalized.js", "r").readlines() // js code
driver = webdriver.Firefox()
result = driver.execute_script(js) // string returned by js function is saved in result
doc = open(path,"w")
doc.write(result)