简体   繁体   中英

Selecting an option from drop down that opens up on hover

请找到附带原始HTML的图片 Need help in selecting an option from a drop that opens up on hover, here is the html i'm currently looking at or you can just look into the attached image -

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

And here is the code i'm trying -

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

使用CSS选择器,您可以通过以下方式单击它:

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

In order to achieve drop down menu selection mentioned in the question, you'll first have to mouse hover to drop down menu then hover mouse over element to select and the click on the element. Following is Java code, but the logic will help you to implement it in 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();

try this (ref: http://allselenium.info/mouse-over-actions-using-python-selenium-webdriver/ )

from selenium.webdriver.common.action_chains import ActionChains

action = ActionChains(driver)

firstLevelMenu = driver.find_element_by_id("yui_3_7_0_4_1390312781452_393") #id of menu, or xpath of menu, whatever
action.move_to_element(firstLevelMenu).perform()

secondLevelMenu = driver.find_element_by_xpath("XPATH_OF_OFFERED")
action.move_to_element(secondLevelMenu).perform()

secondLevelMenu.click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM