2013-05-02 46 views
0

我想单击子菜单中的删除。如何点击一个隐藏的下拉菜单元素使用webdriver,这不是一个选择

我试过下面的代码,但没有任何反应。

wd_handle.execute_script("document.getElementById('optionPanel').hidden=false;") 
mouse.move_to_element(OptionPanel).perform() 
WebDriverWait(wd_handle,10) 
wd_handle.find_element_by_partial_link_text('Delete').click() 

HTML来源:

<div id="optionPanel" style="height: auto; width: auto; left: 126px; top: 368px; display: none; overflow-y: hidden;">' 
<div class="wrapper"> 
    <ul aria-hidden="false" role="menu"> 
    <li role="menuitem"> 
    <li role="menuitem"> 
    <li class="divider" role="menuitem"> 
    <a class="optionPanelLink" tabindex="0" 
    href="#playlistManager/action=delete/selected=701f55af-c5f0-4f31-b34f-964f52be5fef/idx=0"> 
    Delete</a> 
    </li> 
    </ul> 
</div> 
</div> 

我必须点击id为7ba9b231-5fc4-448b-b41a-f236437c182cCount元素上作出上述内容可见。

<li class="playlist viewing"> 
<a id="7ba9b231-5fc4-448b-b41a-f236437c182cLink" class="ellipsis" title="TestList2" href="#playList/name=TestList2/list=7ba9b231-5fc4-448b-b41a-f236437c182c">TestList2</a> 
<span class="entryCount">0</span> 
<a id="7ba9b231-5fc4-448b-b41a-f236437c182cCount" class="customPlaylistSpriteLocation optionSprite" href="#option/playlist=TestList2/selected=7ba9b231-5fc4-448b-b41a-f236437c182c/idx=0"></a> 
</li> 
+0

写出与XPath,然后尝试在隐藏的菜单项,点击执行。希望它能工作。 – 2013-05-02 13:52:28

+0

由于它不在select标签中,因此尝试通过正常的单击操作来处理它 – user2087450 2013-05-02 15:51:21

+0

我尝试了使用所有可能的定位器的正常单击操作,但它没有起作用。 :(我被击中 – Karthick 2013-05-03 07:03:17

回答

0

你确定你的find_element_by_partial_link_text('Delete')工作并返回一个元素?

如果真的不行,我建议使用像cssSelector:"li.divider a"

告诉我这是怎么回事。

+0

我已经尝试过,但它找不到该元素。我想知道如果元素点击ID后仍然隐藏= 7ba9b231-5fc4-448b-b41a-f236437c182cCount – Karthick 2013-05-03 10:37:13

+0

@ user2008902如果你找不到它,那是因为你的元素被隐藏了,而且驱动程序像一个人一样工作,想要点击他无法找到的某个想法,你会看到我的点? – e1che 2013-05-06 06:36:45

-1

首先检查你的子菜单项在哪个地方删除按钮被突出显示......通过使用hover.And以此为参考wrt id你可以点击删除按钮...这是一个代码

WebElement wb=driver.findElement(By.xpath("//li[@datapostid='52f377a10a1de86e33f9bc90']/div")); 
     Actions act=new Actions(driver); 
     act.moveToElement(wb); 
     act.perform(); 
     driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS); 
     wb.findElement(By.cssSelector("span.commdelete")).click(); 
0

替换:

wd_handle.execute_script("document.getElementById('optionPanel').hidden=false;") 

有了:

wd_handle.execute_script("document.getElementById('optionPanel').style.display='block';") 

如果它不工作,然后尝试ū唱他们两个(一个接一个)......

4

您可以使用XPath

import org.openqa.selenium.interactions.Actions; 
    Actions builder = new Actions(driver); 
    builder.moveToElement(driver.findElement(By.xpath("Enter Menu here"))).build().perform(); 
    builder.moveToElement(driver.findElement(By.xpath("Enter Target here"))).build().perform(); 
    driver.findElement(By.xpath("Enter Target here")).click() 

希望这是代码做

相关问题