2

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

asked Jan 25, 2017 at 7:26

1 Answer 1

1

Maybe you can just simply click on the TR element, and let the JavaScript do the rest, like an human interaction.

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()
answered Jan 25, 2017 at 8:41
Sign up to request clarification or add additional context in comments.

5 Comments

I tried tr = browser.find_element_by_xpath('//html/body/TABLE/tr') for hierarchy
<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");'>
<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");'>
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
Test this xpath: //table[@class='font9']//tr[contains(@onclick, 'clearws')]

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.