Python+Selenium登录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python+Selenium登录相关的知识,希望对你有一定的参考价值。
#coding=utf-8 import time from selenium import webdriver #打开浏览器 driver=webdriver.Chrome() #最大化窗口 driver.maximize_window() #设置隐式等待时间 driver.implicitly_wait(8) #打开博客园 driver.get("https://i.cnblogs.com/") #定位账号输入框并输入密码 driver.find_element_by_xpath("//*[@id=‘input1‘]").send_keys("xiaomogu110") #定位到密码输入框并输入密码 driver.find_element_by_xpath("//*[@id=‘input2‘]").send_keys("yH198712!") #定位到登录按钮,并点击 driver.find_element_by_xpath("//*[@id=‘signin‘]").click() #等待2秒 time.sleep(2) #获取元素并检查是否有相应的文本存在 ele_string = driver.find_element_by_xpath("//*[@id=‘post_title_link_7581145‘]").text if (ele_string == u"python+Selenium第一个脚本"): print u"测试成功,结果和预期结果匹配!" driver.close()
以上是关于Python+Selenium登录的主要内容,如果未能解决你的问题,请参考以下文章
Selenium Xpath元素无法定位 NoSuchElementException: Message: no such element: Unable to locate element(代码片段