繁体   English   中英

无法唯一定位用户角色下拉列表

[英]unable to uniquely locate the user-role dropdown

如何唯一定位用户角色下拉列表? 用户角色下拉列表的属性和值与状态相同。 如何使用 css 或 xpath 唯一标识用户角色?

html 两个下拉列表的代码都突出显示

1个

xpath和css的所有组合都试过了,还是找不到

这是实现最终目标的一种方法:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument('disable-notifications')
chrome_options.add_argument("window-size=1280,720")

webdriver_service = Service("chromedriver_linux64/chromedriver") ## path to where you saved chromedriver binary
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)
wait = WebDriverWait(driver, 25)

url = 'https://opensource-demo.orangehrmlive.com/'
driver.get(url)
wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@name="username"]'))).send_keys('Admin')
wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@name="password"]'))).send_keys('admin123')
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@type="submit"]'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//span[text()="Admin"]'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@class="oxd-button oxd-button--medium oxd-button--secondary"]'))).click()
wait.until(EC.presence_of_all_elements_located((By.XPATH, '//div[@class="oxd-select-wrapper"]')))[0].click()
## let's look at the dropdown with options structure
print(wait.until(EC.presence_of_element_located((By.XPATH, '//div[@role="listbox"]'))).get_attribute('outerHTML'))
## do you want to make it an Admin?
# wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@role="listbox"]//span[text()="Admin"]'))).click()
## do you want to make it an ESS?
wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@role="listbox"]//span[text()="ESS"]'))).click()
## moving on to the next dropdown
wait.until(EC.presence_of_all_elements_located((By.XPATH, '//div[@class="oxd-select-wrapper"]')))[1].click()
### please continue yourself

您可以在此处找到 Selenium 文档。

暂无
暂无

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

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