Big Whale~ 2022-05-26 21:04 采纳率: 62.5%
浏览 43
已结题

Selenium与Webdriver进行自动化网页QQ登录时执行第一步后不动了


from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://im.qq.com/index")
driver.find_element_by_xpath("//a[contains(text(),'登录')]").click()
time.sleep(2)
driver.find_element_by_xpath("//input[@id='switcher_plogin']").click()
driver.find_element_by_xpath("//input[@id='u']").clear()
driver.find_element_by_xpath("//input[@id='u']").send_keys("123456789")
driver.find_element_by_xpath("//input[@id='p']").clear()
driver.find_element_by_xpath("//input[@id='p']").send_keys("abcdefg!")
driver.find_element_by_xpath("//input[@value='授权登录']").click()
driver.quit()

img

另外,程序代码中 find_element_by_xpath出现中划线,软件提示弃用,要更改为find_element(By.XPATH,value= xpath)格式,本人尝试修改后,提示出错,请问针对我这串代码如何修改?

  • 写回答

1条回答 默认 最新

  • 逻辑大大 2022-05-27 09:31
    关注

    第九行写错了,不是input标签是a标签

    img


    改为:

    driver.find_element_by_xpath("//*[@id='switcher_plogin']").click()
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月4日
  • 已采纳回答 5月27日
  • 创建了问题 5月26日