2013-05-02 44 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() 

希望這是代碼做

相關問題