硒 - xpath,查找clsass名称不起作用的元素
我正在尝试在门户网站中选择带有名称“ basin”的广播按钮: https:// .gov.in/wris/#/地下水。我正在使用硒来做到这一点。我通过更改类名,XPath等进行了不同的尝试。但是,我遇到了错误:'消息:没有这样的元素:无法找到元素:'。 以下是我尝试过的代码。
from http.server import executable
# from matplotlib import image
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import sys
# from selenium.webdriver.chrome.service import Service
path2 = r"F:\\chromedriver_win32\\chromedriver.exe"
s=Service(r"C:\\Users\\DELL\\OneDrive - Technological University Dublin\\Desktop\\geckodriver-v0.30.0-win64\\geckodriver.exe")
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path=path2)
driver.maximize_window()
url = 'https://indiawris.gov.in/wris/#/groundWater'
driver.get(url)
time.sleep(10)
# basinId = driver.find_element_by_xpath('/html/body/app-root/main/app-gis/as-split/as-split-area[1]/div/div/div[2]/div[1]/div[2]/div[1]/div/div[3]/div[2]/div/groundwater-sidebar/div/div[1]/label[2]')
completeBox = driver.find_element_by_class_name('calcite')
ngStarsBox = completeBox.find_element_by_class_name('views')
print("ngstarss box length",ngStarsBox)
ngStars = completeBox.find_elements_by_class_name("ng-star-inserted")
# basin = completeBox.find_element_by_link_text('Basin')
print("length is:",len(ngStars))
# itemsinBasin =basinId.find_elements_by_class_name("ng-star-inserted")
print("teeeeeeeeeeeeeeeeeeee",ngStars[3])
actionChains = ActionChains(driver)
actionChains.click(ngStars[4]).perform()
I am trying to select the radio button with name 'Basin' in the portal: https://indiawris.gov.in/wris/#/groundWater . I am using selenium for doing that. Different attempts I have made by changing the class name, xpath etc. However, I am getting the error: 'Message: no such element: Unable to locate element:'.
Following is the code I have tried.
from http.server import executable
# from matplotlib import image
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import sys
# from selenium.webdriver.chrome.service import Service
path2 = r"F:\\chromedriver_win32\\chromedriver.exe"
s=Service(r"C:\\Users\\DELL\\OneDrive - Technological University Dublin\\Desktop\\geckodriver-v0.30.0-win64\\geckodriver.exe")
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path=path2)
driver.maximize_window()
url = 'https://indiawris.gov.in/wris/#/groundWater'
driver.get(url)
time.sleep(10)
# basinId = driver.find_element_by_xpath('/html/body/app-root/main/app-gis/as-split/as-split-area[1]/div/div/div[2]/div[1]/div[2]/div[1]/div/div[3]/div[2]/div/groundwater-sidebar/div/div[1]/label[2]')
completeBox = driver.find_element_by_class_name('calcite')
ngStarsBox = completeBox.find_element_by_class_name('views')
print("ngstarss box length",ngStarsBox)
ngStars = completeBox.find_elements_by_class_name("ng-star-inserted")
# basin = completeBox.find_element_by_link_text('Basin')
print("length is:",len(ngStars))
# itemsinBasin =basinId.find_elements_by_class_name("ng-star-inserted")
print("teeeeeeeeeeeeeeeeeeee",ngStars[3])
actionChains = ActionChains(driver)
actionChains.click(ngStars[4]).perform()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了单击盆地,您需要首先切换到所需的iFrame。因为它包裹在iframe中。
代码:
进口:
输出:
屏幕截图:
to be able to click on Basin, you need to first switch to desired iframe. Because it is wrapped inside an iframe.
Code:
Imports:
Output:
Screenshot: