如何在 RIDE 中单击具有 javascript on click 事件的行



我正在尝试通过使用带有Selenium2库的机器人框架工作来单击RIDE IDE中具有javascript onclick函数的行。

<tr class="lstrow" onclick="javascript:selectItem(this);" onmouseover="javascript:this.className='rowhover';" onmouseout="javascript:this.className='row';">

当我在以下 xpath 处执行单击事件时,它说找不到路径上的元素。

/

/*[@id="myList"]/tbody/tr[0]

通过检查元素,我可以确认这一行是否存在。还试图将"rowhover"类指向此 xpath,但仍然没有成功。甚至不确定我是否真的可以在特定的 xpath 上选择一个特定的类。

/

/*[@id="myList"]/tbody/tr[0][contains(@class,'rowhover'(]//不确定是否正确

所需的元素是启用 JavaScript 的元素,因此您需要诱导等待,并且您可以使用以下解决方案之一/两者(杵状(:

  • 蟒蛇解决方案

    • 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
      
  • 您可以在 Robotframework 中找到有关Wait Until Element Is VisibleWait Until Element Is Enabled的详细讨论: Selenium2Lib: Wait till (...(关键字

  • 参考资料:硒2库

最新更新