我正在尝试使用python
的selenium包执行网页的javascript功能我想点击行值
<tr bgcolor="#FFFFFF" style="cursor:hand"
onmouseover="onmouseoverTR(this)"
onmouseout="onmouseoutTR(this)"
onclick="clearwsInfo('2015011800017','2015011800017',this);"
ondblclick='doSelect("auditflowForm","2015011800017");'>
作为
function clearwsInfo(tmpdjbh,tmpsgbh,obj)
{
//判断yesnot existentTR已被existent,如果yes就还原到原来的样式
if ( obj !="" && obj !=null )
{
if(preTR!=""){
preTR.style.background='#FFFFFF';
}
obj.style.background='#c9e3ef';
preTR=obj;
}
var forms = "parent.document." + gFormName + ".";
parent.document.getElementById("tmpsgbh").value = tmpsgbh;
parent.document.getElementById("tmpdjbh").value = tmpdjbh;
loadDwr(tmpdjbh,tmpsgbh) ;
parent.document.wsList.location.href = "http://114.255.167.200:8092/cidasEN/extend/wsTreeAction.do?cs=1&sgbh="+ tmpsgbh;
}
我试过的代码是
iedriver = 'C:\Users\IEDriverServer.exe'
browser = webdriver.Ie(iedriver)
browser.get ('http://114.255.167.200:8092/cidasEN/extend/LookAuditflowListAction.do')
browser.execute_script("clearwsInfo('2015011800017','2015011800017',this)")
我收到了错误
Traceback (most recent call last):
File "D:\surendra\Neon-WorkSpace\EvidenseData\selinum.py", line 25, in <module>
browser.execute_script("clearwsInfo ('2015011800017','2015011800017',this)")
File "C:\Python27\lib\site- packages\selenium\webdriver\remote\webdriver.py", line 465, in execute_script
'args': converted_args})['value']
File "C:\Python27\lib\site- packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site- packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: JavaScript error
如何执行clearwsInfo函数
答案 0 :(得分:1)
也许你只需点击TR元素,然后让JavaScript完成其余工作,就像人工互动一样。
iedriver = 'C:\Users\IEDriverServer.exe'
browser = webdriver.Ie(iedriver)
browser.get ('http://114.255.167.200:8092/cidasEN/extend/LookAuditflowListAction.do')
tr = browser.find_element_by_xpath('//table[@class='font9']//tr[contains(@onclick, 'clearws')]')
tr.click()