简体   繁体   English

Python Selenium选择下拉菜单选项

[英]Python Selenium Select Drop Down Menu Option

I'm trying to get forms filled out on this auction website. 我正在尝试在此拍卖网站上填写表格。 Right now I need to figure out how to select the option on a hover-menu. 现在,我需要弄清楚如何在悬停菜单上选择该选项。 I tried looking at other questions here but they all had XPATH or CSS as ways for identifying the sub menu option. 我尝试在这里查看其他问题,但是它们都具有XPATH或CSS作为标识子菜单选项的方式。 I can't inspect the option with my browser and I would appreciate any insights! 我无法使用浏览器检查该选项,我将不胜感激!

菜单和子菜单截图

What the code for for the Assignment button: 分配按钮的代码是什么:

Google Chrome的HTML代码

HTML 2 - when I hover over "Add Auction Assignment" it seems like it makes something called a javascript pop up, but I don't know. HTML 2-当我将鼠标悬停在“添加拍卖分配”上时,似乎弹出了一个称为javascript的内容,但我不知道。

Below is the code I have so far and the approach I attempted. 下面是到目前为止的代码和尝试的方法。 It does find the assignment button and it does hover over it but it always times out. 它确实找到了分配按钮,并且将鼠标悬停在该按钮上,但始终超时。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import Select

browser = webdriver.Chrome("C:\Program Files\chromedriver_win32/chromedriver.exe")

actions = ActionChains(browser)

#Go to the desired website
browser.get("http://www.autoims.com/external/index.jsp")

usrname_box = browser.find_element_by_xpath('//*[@id="loginUsername"]')
pw_box =  browser.find_element_by_xpath('//*[@id="password"]')
login_button =  browser.find_element_by_xpath('//*[@id="submit"]')

#login process here

wait = WebDriverWait(browser, 10)

for vin in df['VIN']:
    assignments = wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="_img0"]')))
    ActionChains(browser).move_to_element(assignments).perform()

    add_assignment = wait.until(EC.visibility_of_element_located((By.XPATH, "  HELP :(  "))) #always fails
    ActionChains(browser).move_to_element(add_assignment).click().perform()

did you try to find the html code of sub menu from the end of page souce, for some JQuery navbar plugin, it append the html code of sub menu to the end of body tag. 您是否尝试从页面来源的末尾找到子菜单的html代码,对于某些JQuery导航栏插件,它将子菜单的html代码附加到body标签的末尾。

you can scroll down to the end of page source firstly, then hover on the Assignment menu, meanwhile watch any new html code appended or any html code change. 您可以先向下滚动到页面源末尾,然后将鼠标悬停在“分配”菜单上,同时观看添加的任何新的HTML代码或任何html代码更改。

only when we see the html code of sub menu, we can know how to locator it in script. 只有当我们看到子菜单的html代码时,我们才能知道如何在脚本中定位它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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