Selenium---Python3---弹框处理
#!/usr/bin/env python from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains import time class driver_class(object): #建立一个Chrome对象 def __init__(self): self.driver = webdriver.Chrome() def driver_dialog(self): self.driver.get('https://www.baidu.com/') #点击登陆链接 login = self.driver.find_element_by_css_selector('.lb[name="tj_login"]') #点击登陆按钮 ActionChains(self.driver).double_click(login).perform() #通过二次定位找到用户输入框 div = self.driver.find_element_by_class_name("tang-content").find_element_by_name("userName") div.sendkeys("username") #输入登录密码 self.driver.find_element_by_name("password").send_keys("password") #点击登录 self.driver.find_element_by_id("TANGRAM__PSP_10__submit").click() time.time(10) self.driver.close() if __name__ == "__main__": a = driver_class() a.driver_dialog()