python - Selenium 找到元素并单击它

标签 python selenium

我试图让 Selenium 单击查看所有公司按钮,但我不确定我做错了什么。它返回未找到元素

html代码

<div class="screener-toggles">
  <div class="buttons">
    <span class="button selected" data-name="advanced-screener">Search by Screener<span data-name="advanced-screener" class="arrow selected"></span></span>
    <span class="button" data-name="alpha-factors">Search by Alpha Factors<span data-name="alpha-factors" class="arrow"></span></span>
    <span class="button" data-name="all-companies">View All Companies<span data-name="all-companies" class="arrow"></span></span>
  </div>
</div>

我写的Python代码

element1 = driver.find_elements_by_class_name('View All Companies')
element1.click()
# I have tried all-companies instead of View All Companies as well. But still doesn't work

我不应该使用find_elements_by_class_name吗?

非常感谢任何有关我做错的事情的建议!

最佳答案

尝试 xpath: "//span[contains(text(),'查看所有公司')]"

关于python - Selenium 找到元素并单击它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36262033/

相关文章:

java - Selenium 编程 -- 按 F12,现在如何从 Chrome 复制粘贴代码?

python - __init__.py 的用法

python - 如何在 Windows 和 Python 2.7 上模拟 os.path.samefile 行为?

java - 通过 Java WebApp 使用 Runtime.exec 运行脚本

java - 数据提供者和断言

python - 用selenium填写登录信息

python - Selenium 不适用于为避免检测而修改的 chromedriver

平均安装中的Python错误

python - Python 中的装箱时间列

testing - 我如何以编程方式控制 Selenium RC 的启动和停止