如何将鼠标一个接一个地悬停在多个元素上,然后使用 Selenium 和 Python 单击 OrangeHRM 网站中的一个元素
How to Mouse Hover multiple elements one by one and then click on an element within OrangeHRM website using Selenium and Python
在网站 https://opensource-demo.orangehrmlive.com/ 上,我试图打开管理框,然后打开用户管理,然后单击用户。我不明白我的错误在哪里。它给我错误 AttributeError: move_to requires a WebElement.我已经阅读了其他类似我的相关问题,但仍然无法完成工作。
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver")
driver.get("https://opensource-demo.orangehrmlive.com/")
driver.maximize_window()
time.sleep(2)
driver.find_element_by_id("txtUsername").send_keys("Admin")
driver.find_element_by_id("txtPassword").send_keys("admin123")
driver.find_element(By.ID, "btnLogin").click()
admin=driver.find_elements_by_xpath("//*[@id='menu_admin_viewAdminModule']/b")
userManagment=driver.find_elements_by_xpath("//*[@id='menu_admin_UserManagement']")
users=driver.find_elements_by_xpath("//*[@id='menu_admin_viewSystemUsers']")
time.sleep(1)
actions=ActionChains(driver)
actions.move_to_element(admin).move_to_element(userManagment).move_to_element(users).click().perform()
要在 OrangeHRM 内登录, on Admin then on User Management and finally to on Users you you need to induce WebDriverWait for the visibility_of_element_located()
and you can use the following :
driver.get("https://opensource-demo.orangehrmlive.com/")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#txtUsername"))).send_keys("Admin")
driver.find_element(By.ID, "txtPassword").send_keys("admin123")
driver.find_element(By.ID, "btnLogin").click()
ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a#menu_admin_viewAdminModule")))).perform()
ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a#menu_admin_UserManagement")))).perform()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#menu_admin_viewSystemUsers"))).click()
浏览器快照:
在网站 https://opensource-demo.orangehrmlive.com/ 上,我试图打开管理框,然后打开用户管理,然后单击用户。我不明白我的错误在哪里。它给我错误 AttributeError: move_to requires a WebElement.我已经阅读了其他类似我的相关问题,但仍然无法完成工作。
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver")
driver.get("https://opensource-demo.orangehrmlive.com/")
driver.maximize_window()
time.sleep(2)
driver.find_element_by_id("txtUsername").send_keys("Admin")
driver.find_element_by_id("txtPassword").send_keys("admin123")
driver.find_element(By.ID, "btnLogin").click()
admin=driver.find_elements_by_xpath("//*[@id='menu_admin_viewAdminModule']/b")
userManagment=driver.find_elements_by_xpath("//*[@id='menu_admin_UserManagement']")
users=driver.find_elements_by_xpath("//*[@id='menu_admin_viewSystemUsers']")
time.sleep(1)
actions=ActionChains(driver)
actions.move_to_element(admin).move_to_element(userManagment).move_to_element(users).click().perform()
要在 OrangeHRM 内登录,visibility_of_element_located()
and you can use the following
driver.get("https://opensource-demo.orangehrmlive.com/")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#txtUsername"))).send_keys("Admin")
driver.find_element(By.ID, "txtPassword").send_keys("admin123")
driver.find_element(By.ID, "btnLogin").click()
ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a#menu_admin_viewAdminModule")))).perform()
ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a#menu_admin_UserManagement")))).perform()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#menu_admin_viewSystemUsers"))).click()
浏览器快照: