Javascript 使用selenium跟踪html元素中的更改
它是一个动态元素,因此我必须给出完整的Xpath。它是一个下拉列表 如果用户来到此页面并更改了下拉选项,是否有任何方法可以自动将我代码中的此xpath替换为新选择的选项的xpath,以便下次执行代码时它转到新选择的选项Javascript 使用selenium跟踪html元素中的更改,javascript,python,selenium,selenium-webdriver,beautifulsoup,Javascript,Python,Selenium,Selenium Webdriver,Beautifulsoup,它是一个动态元素,因此我必须给出完整的Xpath。它是一个下拉列表 如果用户来到此页面并更改了下拉选项,是否有任何方法可以自动将我代码中的此xpath替换为新选择的选项的xpath,以便下次执行代码时它转到新选择的选项 from selenium import webdriver from time import sleep username = "" password = "" url="" chrome_options = we
from selenium import webdriver
from time import sleep
username = ""
password = ""
url=""
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches",["enable-automation"])
driver = webdriver.Chrome(options=chrome_options, )
driver.get(url)
driver.find_element_by_xpath("//input[@placeholder='Enter User Id']").send_keys(username)
driver.find_element_by_xpath("//input[@placeholder='Enter Password']").send_keys(password)
driver.find_element_by_xpath('//button[normalize-space()="Sign In"]').click()
sleep(4)
driver.get("")
sleep(2)
driver.find_element_by_class_name('css-1hwfws3').click()
driver.find_element_by_xpath("/html/body/div/div/div/div/div[2]/div/div/div/div[2]/div/div[5]").click()
driver.fullscreen_window()
我是新手,请帮帮我
谢谢你你能为下拉列表共享html或任何图像吗?@Mat L1 L 2请将你的问题包含在html中。你可以使用类名选择下拉列表。驱动程序。通过类名称(“css-k1-menu”)查找元素。单击()
driver.find_element_by_xpath("/html/body/div/div/div/div/div[2]/div/div/div/div[2]/div/div[5]").click()