# -*- coding:utf-8 -*-
# 作者:NoamaNelson
# 日期:2022/5/17
# 文件名称:selen_by.py
# 作用:验证By方法
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
# driver.find_element_by_id("kw").send_keys("NoamaNelson")
driver.find_element(By.ID, "kw").send_keys("NoamaNelson")
time.sleep(1)
# driver.find_element_by_id("kw").send_keys(Keys.ENTER)
driver.find_element(By.ID, "kw").send_keys(Keys.ENTER)
driver.maximize_window()
time.sleep(0.5)
# driver.find_element_by_id("kw").send_keys(Keys.CONTROL,"a")
driver.find_element(By.ID, "kw").send_keys(Keys.CONTROL, "a")
time.sleep(0.5)
# driver.find_element_by_id("kw").send_keys("N")
driver.find_element(By.ID, "kw").send_keys("N")
# su = driver.find_element_by_id("su")
su = driver.find_element(By.ID, "su")
ActionChains(driver).click(su).perform()
time.sleep(1)
driver.quit()
评论