我试图找到下拉列表并选择一个选项。我使用的代码如下
from selenium import webdriver
driver=webdriver.Chrome(r"C:\Users\nithi\Downloads\chromedriver.exe")
driver.get('https://parivahan.gov.in/parivahan/')
VehicleServicesButton = driver.find_element_by_xpath('//*[@id="block-block-9"]/div/div[1]/p/a')
VehicleServicesButton.click()
OtherStatesButton = driver.find_element_by_xpath('//*[@id="node-1978"]/div/div/div/div/div[3]/a/div/img')
OtherStatesButton.click()
driver.maximize_window()
driver.implicitly_wait(20)
driver.find_element_by_id('state_cd_label').click()
我在最后一行代码中遇到以下错误
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="state_cd_label"]"}
(Session info: chrome=88.0.4324.104)
你很快就能做到。单击图像时,新选项卡打开,因此要在新窗口上操作,您必须将驾驶员焦点从父选项卡切换到新选项卡上
一旦你这样做,例外情况就会消失
要切换到新选项卡,只需在上述代码的最后一行之前添加此代码
输出-
相关问题 更多 >
编程相关推荐