algorithm6 2023-09-05 20:42 采纳率: 76.2%
浏览 8
已结题

selenium的问题

我在学习selenium的过程中,编写如下程序:

from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.common.by import By

options = webdriver.EdgeOptions()
service = EdgeService(executable_path='msedgedriver.exe')
browser = webdriver.Edge(service=service, options=options)
browser.get('https://www.taobao.com')

login_btn = browser.find_element(By.NAME, '登录')

运行报错:

img

img


请问要怎么修改

  • 写回答

2条回答 默认 最新

  • 不氪金玩家 2023-09-05 20:59
    关注

    这个错误是页面上没有这个元素,打开浏览器,确实没有你写的这个登录按钮元素,你要定位的元素表达式写错了

    from selenium import webdriver
    from selenium.webdriver.edge.service import Service as EdgeService
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as ex
    
    options = webdriver.EdgeOptions()
    service = EdgeService(executable_path='msedgedriver.exe')
    browser = webdriver.Edge(service=service, options=options)
    browser.get('https://www.taobao.com')
    
    WebDriverWait(driver, 15).until(ex.visibility_of_element_located((By.XPATH, "//a[text()='亲,请登录']")))    # 等待这个按钮的出现
    login_btn = browser.find_element(By.XPATH, "//a[text()='亲,请登录']")
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月17日
  • 已采纳回答 9月9日
  • 创建了问题 9月5日

悬赏问题

  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数
  • ¥15 ADS时域 连续相位观察方法
  • ¥15 Opencv配置出错
  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused