2014-03-27 120 views
0

使用Selenium WebDriver,我试图点击Manual Testing选项Testing菜单http://guru99.com/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> 
    . 
    . 
    . 
+2

请发表你的HTML代码片断,如果可能的 – Sighil

+0

更新与HTML代码段的问题。 – TDHM

回答

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 
+0

这不是问题 - “无法定位元素”找到我提到的元素,但无法从下拉列表中选择列表元素。 – TDHM

+0

我不是说你正在搜索的元素不存在,但是它真的需要什么?....例如,考虑在方形框顶部的“红色按钮”,要求按红色按钮'和**没有在方盒子的顶部表面...在你的情况下,李如方盒子和achor标签就像红色的按钮。 – Amith

+0

啊,明白了。我试过了,但是它给'mt = $ driver.find_element(:partial_link_text,“手动测试”)提供错误'无法找到元素''我不明白,为什么会发生这种情况是正确的? – TDHM