2014-01-21 32 views
0

Please find the attached image with its original HTML開闢了選擇從懸停開闢了一個下降的一個選項時需要幫助,這裏是我目前看HTML或者你可以考慮附加的圖像 -選擇從下拉選項下,關於懸停

<ul id="yui_3_7_0_4_1390312781452_393" class="dropdown-menu"> 

<li id="yui_3_7_0_4_1390312781452_392" class="action" value="4001"> 

    Promising 

</li> 
<li class="action" value="4003"> 

    In Discussion 

</li> 
<li class="action" value="4004"> 

    Phone screen 

</li> 
<li class="action" value="4005"> 

    Interview 

</li> 
<li class="action" value="4006"> 

    Offered 

</li> 
<li class="action" value="4007"> 

    Hired 

</li> 

這裏是我想要的代碼 -

strings = driver.find_elements_by_class_name("action").text   
    for text in strings: 
     if text=='Offered': 
      text.click() 

回答

0

使用CSS選擇器,你可以做點擊:

driver.find_element_by_css_selector("ul.dropdown-menu[id^='yui'] li[value='4006']").click() 
+0

這不工作雖然:(將不得不嘗試一些棘手的事情。 – user3121891

0

爲了實現下拉問題中提及的菜單選擇,你首先必須鼠標懸停下拉菜單,然後鼠標懸停在元素來選擇和元素上的點擊。以下是Java代碼,但邏輯將幫助你在Python中實現它:

WebElement dropDownMenu = driver.findElement(By.id("yui_3_7_0_4_1390312781452_393")); 
WebElement elementToSelect = driver.findElement(By.xpath(".//li[contains(text(), 'Offered')")); 

Actions action = new Actions(driver); 
action.moveToElement(dropDownMenu).moveToElement(elementToSelect).click().build().perform();