gpt4 book ai didi

python Selenium : find and click an element

转载 作者:太空宇宙 更新时间:2023-11-03 12:12:23 24 4
gpt4 key购买 nike

如何使用 Python 简单地找到包含文本/id/等的链接,然后单击该元素?

我的导入:

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys

转到我的 URL 的代码:

browser = webdriver.Firefox() # Get local session of firefox
browser.get(myURL) # Load page
#right here I want to look for element containing "Click Me" in the text
#and then click it

最佳答案

查看 WebDriver 类的方法列表 - http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html

例如,通过ID查找元素并点击它,代码如下所示

element = browser.find_element_by_id("your_element_id")
element.click()

关于 python Selenium : find and click an element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9798273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com