Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用selenium跟踪html元素中的更改_Javascript_Python_Selenium_Selenium Webdriver_Beautifulsoup - Fatal编程技术网

Javascript 使用selenium跟踪html元素中的更改

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

它是一个动态元素,因此我必须给出完整的Xpath。它是一个下拉列表

如果用户来到此页面并更改了下拉选项,是否有任何方法可以自动将我代码中的此xpath替换为新选择的选项的xpath,以便下次执行代码时它转到新选择的选项

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