Python中文
首页
教程
问答
标签
搜索
登录
注册
通过\u类\u名称查找\u元素\u,当元素明显存在时,返回NoTouchElementException
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在使用Selenium编写一个脚本,该脚本应该定期从Box:<a href="https://osu.app.box.com/v/covid-19publicdata" rel="nofollow noreferrer">https://osu.app.box.com/v/covid-19publicdata</a>下载这个.csv文件,但是我在查找button元素时遇到了问题</p> <p>按钮的HTML代码如下所示:</p> <pre><code><button class="btn tooltip-target tooltip-element-attached-top tooltip-element-attached-center tooltip-target-attached-bottom tooltip-target-attached-center" type="submit" data-resin-item_id="725957383895" data-resin-target="download" tabindex="0"><span class="btn-content"><span>Download</span></span></button> </code></pre> <p>为了找到按钮并单击它,我编写了以下代码(在导入适当的库后运行):</p> <pre><code>driver = webdriver.Chrome('C:/Users/calle/chromedriver') driver.get("https://osu.app.box.com/v/covid-19publicdata") button = driver.find_element_by_class_name("btn tooltip-target tooltip-element-attached-top tooltip-element-attached-center tooltip-target-attached-bottom tooltip-target-attached-center") button.click() </code></pre> <p>然而,尽管我搜索的类名与驱动程序上的类名完全相同,但它在“find element”行上返回NoSuchElementException。我还没有找到任何关于为什么会发生这种情况的信息。我不是一个计算机科学家,所以在这方面的任何帮助都将不胜感激。我也不太喜欢这种特殊的方法,所以如果有更简单的方法,我会洗耳恭听</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>代码的问题是它是一个复合类名,是多个类名。它不适用于类名。有一个更容易使用的选择器</p> <pre><code>button=driver.find_element_by_css_selector("button[data-resin-target='download']") button.click() </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
3 回答
如何在python中从数据帧列表中删除引号
2 回答
如何在python中从数据帧创建列表
10 回答
如何在Python中从数据帧创建嵌套的JSON
2 回答
如何在Python中从数据帧显示wordcloud
6 回答
如何在Python中从数据帧的时间戳中删除字符
6 回答
如何在Python中从数据帧绘制简单绘图?
4 回答
如何在python中从数据帧行提取具有特定长度的范围?
8 回答
如何在python中从数据帧设置dict中的值
10 回答
如何在Python中从数据库中获得一个结果
9 回答
如何在python中从数据框中绘制分类条形图
3 回答
如何在Python中从数据框中选择特定细节?
8 回答
如何在python中从数据集中删除unicode
4 回答
如何在python中从数据集中删除某些数值?
3 回答
如何在python中从数据集中选择行
7 回答
如何在Python中从数组中删除元素
4 回答
如何在python中从数组中删除单个倒逗号?
1 回答
如何在python中从数组中删除对象?
2 回答
如何在python中从数组中删除引号
10 回答
如何在python中从数组中删除所有最小值
4 回答