问题
I am trying to click a row that has a javascript onclick function in RIDE IDE by using Robot Frame Work with Selenium2 library.
<tr class="lstrow" onclick="javascript:selectItem(this);" onmouseover="javascript:this.className='rowhover';" onmouseout="javascript:this.className='row';">
When i perform click event at following xpath, it says element at path not found.
//*[@id="myList"]/tbody/tr[0]
By inspecting the element, I can confirm this row is there. Also tried to pin point the 'rowhover' class at this xpath but still not successful. Not even sure if I really can select a specific class at a specific xpath.
//*[@id="myList"]/tbody/tr[0][contains(@class,'rowhover')] //Not sure if it is right
回答1:
The desired element is a JavaScript enabled element so you need to induce wait and you can use either/both (clubbing up) of the following solutions:
Python Solution
Wait Until Element Is Visible
:Wait Until Element Is Visible xpath=//tr[@class="lstrow"] 20 seconds Set Focus To Element xpath=//tr[@class="lstrow"] # invoke click
Wait Until Element Is Enabled
:Wait Until Element Is Enabled xpath=//tr[@class="lstrow"] 20 seconds Set Focus To Element xpath=//tr[@class="lstrow"] # invoke click
You can find a detailed discussion about
Wait Until Element Is Visible
andWait Until Element Is Enabled
in Robotframework: Selenium2Lib: Wait Until (…) KeywordsReference: Selenium2Library
来源:https://stackoverflow.com/questions/52815184/how-to-click-a-row-that-has-javascript-on-click-event-in-ride