【问题标题】:python - Weird unclear error with selenium [closed]python - 硒的奇怪不清楚错误[关闭]
【发布时间】:2014-03-13 17:10:42
【问题描述】:

我的代码:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException

site = "https://blockchain.info/wallet/login"
identifier = "myIdentifier"


browser = webdriver.Firefox()
browser.get(site)
browser.find_element_by_xpath('/html/body/div[5]/div[4]/div/div/div[2]/div/div/input'.send_keys(identifier)

我运行它并收到此错误:
(来源:gyazo.com

大图:http://gyazo.com/897fe2b83db36585b3521cc1a06aa832

我在该行之后尝试了诸如评论之类的操作,上下移动它,但我不知道这里有什么问题

【问题讨论】:

  • 不知道是不是这样,但括号在你的最后一行不匹配。您可能想在send_keys 之前添加一个结束语?
  • 这是您的代码的图像,您看到了什么错误?
  • 不错的收获。谢谢你。解决了
  • @usmcs,唯一的错误是“无效语法”,但正如不知道所说,我遗漏了一个括号
  • 这么长的行完美地演示了为什么像 pep8 这样的编码标准是好的。如果断线和正确缩进的行会更快地看到他的问题。

标签: python selenium selenium-webdriver


【解决方案1】:

替换:

browser.find_element_by_xpath('/html/body/div[5]/div[4]/div/div/div[2]/div/div/input'.send_keys(identifier)

与:

browser.find_element_by_xpath('/html/body/div[5]/div[4]/div/div/div[2]/div/div/input').send_keys(identifier)

观看结束 ) - 首先找到一个元素,然后将密钥发送给它。

【讨论】:

    【解决方案2】:

    你错过了一个右括号。 试试这个。

    browser = webdriver.Firefox()
    browser.get(site)
    browser.find_element_by_xpath('/html/body/div[5]/div[4]/div/div/div[2]/div/div/input').send_keys(identifier)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 2017-05-28
      • 2011-08-14
      • 1970-01-01
      • 2023-03-16
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多