无法从下拉列表中单击列表元素

时间:2014-03-27 06:24:22

标签: ruby selenium selenium-webdriver

使用Selenium WebDriver,我在Manual Testing上将鼠标悬停在Testing选项后,点击Manual Testing菜单中的Testing选项}。为了实现上述目标,我做了以下 -

testing = $driver.find_element(:xpath, "//li[@class='item118 parent']")
mt = $driver.find_element(:xpath, "//li[@class='item119']/a")

$driver.action.move_to(testing).move_to(mt).perform
mt.click

但是,有时代码上的第3行错误 -

Selenium::WebDriver::Error::MoveTargetOutOfBoundsError: Offset within element ca
nnot be scrolled into view: (85, 21): http://guru99.com/software-testing.html

有时上面代码中第4行的错误 -

Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently vis
ible and so may not be interacted with

请帮我解决此问题,而不执行javascript

这是HTML代码 -

<li class="item118 parent">
  <a class="item" href="/software-testing.html"> Testing </a>
   <span class="dropdown-spacer"></span>
 <div class="dropdown columns-1 " style="width:180px;">
   <div class="column col1" style="width:180px;">
     <ul class="l2">
       <li class="item119">
         <a class="item" href="/software-testing.html"> Manual Testing </a>
      </li>
     .
     .
     .

1 个答案:

答案 0 :(得分:0)

您可以尝试partial_link_text

testing = $driver.find_element(:partial_link_text, "Testing")
$driver.action.move_to(testing).perform
mt = $driver.find_element(:partial_link_text, "Manual Testing")
mt.click