需要帮助从悬停时打开的drop中选择一个选项,这里是我正在查看的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 :(得分:0)
使用CSS选择器,您可以通过执行以下操作单击它:
driver.find_element_by_css_selector("ul.dropdown-menu[id^='yui'] li[value='4006']").click()
答案 1 :(得分: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();
答案 2 :(得分:0)
尝试一下(参考:http://allselenium.info/mouse-over-actions-using-python-selenium-webdriver/)
def WriteToCSV(OutPutFile, dataOut):
global logger
try:
with open(OutPutFile, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter='|', quotechar='"', quoting=csv.QUOTE_ALL)
for data in dataOut :
writer.writerow(data)