gpt4 book ai didi

python - selenium execute_script 给出错误

转载 作者:太空宇宙 更新时间:2023-11-04 05:15:28 24 4
gpt4 key购买 nike

我正在尝试使用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函数

最佳答案

也许您只需点击 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()

关于python - selenium execute_script 给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41845722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com