Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

selenium execute_script gives error

I am trying to execute the javascript function of webpage using the selenium package of python

I would like to click on row value

<tr bgcolor="#FFFFFF" style="cursor:hand" 
 onmouseover="onmouseoverTR(this)" 
 onmouseout="onmouseoutTR(this)" 
 onclick="clearwsInfo('2015011800017','2015011800017',this);"
 ondblclick='doSelect("auditflowForm","2015011800017");'> 

function as

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;
} 

code which I tried is

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)")

I got an error

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

how can I execute the function clearwsInfo

Answer*

Draft saved
Draft discarded
Cancel
5
  • I tried tr = browser.find_element_by_xpath('//html/body/TABLE/tr') for hierarchy Commented Jan 25, 2017 at 13:42
  • <body bottomMargin=0 leftMargin=0 topMargin=0 > <TABLE border="1" bordercolorlight="#6D6D6D" cellspacing="1" class=font9 #4D5E8C 1px solid" > <tr bgcolor="#CCCCCC" > <td class="title_1" width ='6%' align="center">case number</td> <td class="title_1" width ='10%' align="center">time of accident</td> </tr> <tr bgcolor="#FFFFFF" style="cursor:hand" onclick="clearwsInfo('2015011800017','2015011800017',this);" ondblclick='doSelect("auditflowForm","2015011800017");'> Commented Jan 25, 2017 at 13:43
  • <body bottomMargin=0 leftMargin=0 topMargin=0 > <TABLE border="1" bordercolorlight="#6D6D6D" cellspacing="1" class=font9 #4D5E8C 1px solid" > <tr bgcolor="#CCCCCC" > <td class="title_1" width ='6%' align="center">case number</td> <td class="title_1" width ='10%' align="center">time of accident</td> </tr> <tr bgcolor="#FFFFFF" style="cursor:hand" onclick="clearwsInfo('2015011800017','2015011800017',this);" ondblclick='doSelect("auditflowForm","2015011800017");'> Commented Jan 25, 2017 at 13:44
  • i got the error raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with xpath == //html/body/TABLE/tr Commented Jan 25, 2017 at 13:44
  • Test this xpath: //table[@class='font9']//tr[contains(@onclick, 'clearws')] Commented Jan 25, 2017 at 15:00

lang-py

AltStyle によって変換されたページ (->オリジナル) /