from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
import os
try:
path = "C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chromedriver"
driver=webdriver.Chrome(path)
driver.maximize_window()
driver.get(“https://www.jd.com/”)
elem=driver.find_element_by_link_text(“手机”)
ActionChains(driver).move_to_element(elem).perform()
time.sleep(3)
old_phone=driver.find_element_by_link_text(“老人机”)
old_phone.click()
#driver.save_screenshot(“oldphone.png”)
#浏览器句柄切换
handles=driver.window_handles
current_handle=driver.current_window_handle
for handle in handles:
if handle!=current_handle:
driver.switch_to.window(handle)
driver.save_screenshot(“file.png”)
finally:
time.sleep(3)
driver.quit()
执行报如下错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:“link text”,“selector”:“老人机”}
(Session info: chrome=75.0.3770.142)
问:为什么鼠标没有在手机这里悬停