zoukankan      html  css  js  c++  java
  • python3+selenium3在百度首页中定位登录按钮并登陆

    from selenium import webdriver
    from time import sleep

    driver=webdriver.Firefox()

    driver.get("https://www.baidu.com/")

    #定位登录按钮
    driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[4]/a").click()
    sleep(2)

    #点击弹出窗口的“账号密码登陆”方式
    driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_11__footerULoginBtn']").click()
    sleep(2)

    #定位窗口中的用户名和密码输入区域
    driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_11__userName']").send_keys("用户名")
    sleep(2)
    driver.find_element_by_name("password").send_keys("密码")
    sleep(2)

    点击登陆
    driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_11__submit']").click()



    标注问题:用了id、name、linktext都不行,主要是定位不到登录按钮,也不知道是为什么,并且报错是

    Traceback (most recent call last):
    File "F:/pycharm/TEST/Fnid_Element/test.py", line 24, in <module>
    driver.find_element_by_name("tj_login").click()
    File "F:pycharmvenvlibsite-packagesseleniumwebdriver emotewebelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
    File "F:pycharmvenvlibsite-packagesseleniumwebdriver emotewebelement.py", line 633, in _execute
    return self._parent.execute(command, params)
    File "F:pycharmvenvlibsite-packagesseleniumwebdriver emotewebdriver.py", line 321, in execute
    self.error_handler.check_response(response)
    File "F:pycharmvenvlibsite-packagesseleniumwebdriver emoteerrorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.ElementNotInteractableException: Message:

    目前上网查了原因没搞清楚是为啥,如果有大佬告知一下也是感激不尽。

    现在是用Xpath定位比较方便

  • 相关阅读:
    选项卡
    使用script创建标签添加属性值和添加样式
    判断表单不能为空(表格形式的)
    数组
    关于meta元信息元素
    js判断数据类型
    Ising模型的Metropolis模拟中的组态阻塞和振荡
    python 画能级图
    python 调用 shell 命令,制作用户界面
    打包 python 程序,变成一个可执行文件
  • 原文地址:https://www.cnblogs.com/HYL1003597280/p/14290377.html
Copyright © 2011-2022 走看看