python - Selenium 无法使用 python 定位错误?
问题描述
在将 selenium im 与 python 结合使用时出现以下错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/main/article/section/form/div[1]/div[2]/div/div/div/div/div/div/input"}
我的 python 脚本如下所示:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
import time
import random
import string
driver = webdriver.Chrome("D:\Programmieren\Python\Python\pybo\chromedriver.exe")
driver.get("https://www.langenscheidt.com/jugendwort-des-jahres")
time.sleep(10)
driver.find_element_by_xpath("/html/body/main/article/section/form/div[1]/div[2]/div/div/div/div/div/div/input")
目标html是这样的:
<input aria-labelledby="question-title-463803684" id="463803684" aria-required="true" data-sm-open-single="true" class="wds-input wds-input--lg qt-input_text text" name="463803684" size="100" value="">
解决方案
所以我检查了网站,您要填写的表格包含(嵌入)html,这意味着另一对标签内有标签。我不知道如何解析,但如果您只想填写该表格,则有一个单独的 URL:
https://www.surveymonkey.com/r/7JZRVLJ。
这是相同的表格,只是没有嵌入到以前的网站中。您可以将此 URL 用于您的 selenium 自动化。
推荐阅读
- python - 如何从 Python 编程中的输入代码中删除空格(多个空格、制表符、下一行)?
- sql - WHERE NOT price =(从产品中选择价格)不起作用。(SQL)
- apache-spark - 初始化 SparkContext 后是否可以更改 SparkContext.sparkUser()?
- javascript - 如何滚动在 onClick 事件之前隐藏的“onClick”组件
- d3.js - D3饼图只旋转弧线
- r - 在一个 CSV 单元格中导入矢量 R
- kotlin - 在 kotlin 中初始化列表
- sql - 在这种情况下,“OVER(ORDER BY ...)”如何以及为什么起作用?
- amazon-dynamodb - 如何使用云形成更新 dynamodb 表
- mysql - 我想在mysql中获取当年其他月份销售额最大的三个月的数据