Python/Selenium - Chrome Web Driver,点击操作

3
我在使用Python中的Selenium和Chrome Web Driver编码点击操作时遇到了问题。我花了一些时间在谷歌上找到资料,发现我必须使用另一个Selenium进程才能在Google Chrome中执行点击操作,这对我来说没有意义(难道不应该在调用webdrive.Chrome时完成吗?)。尽管我无法找到任何其他方法进行点击,无论是在线还是通过查看Selenium模块。
以下是我的代码,请帮忙看看!感谢!
编辑:我在Selenium中找到了ActionChains模块,但似乎也无法使用。更新了我的代码,但仍然卡住了。难道ChromeDriver真的不支持点击操作吗?
import selenium
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time

chromeOps = webdriver.ChromeOptions()
chromeOps._binary_location = "C:\\Applications\\Browser\\Chrome.exe"
chromeOps._arguments = ["--enable-internal-flash"]

browser = webdriver.Chrome("C:\\Applications\\Browser\\chromedriver.exe", port=4445, chrome_options=chromeOps)
time.sleep(3)

browser.get("http://example.com")

##selenium.selenium("127.0.0.1", 4445,'*Chrome.exe', 'https://example.com').click("//a[contains(@href,'http://example.com/link')]")

webdriver.ActionChains(browser).click(on_element='//a[contains(@href,"http://example.com/link")]')
1个回答

8

当简单的事情就在你面前时,我讨厌这种感觉。

clickme = browser.find_element_by_xpath('//a[contains(@href,"http://example.com/link")]')
clickme.click()

也许是因为他不知道,所以他才会问。 - dannyroa
4
呵呵,提问和回答的人都是同一个人。 - Sandeep Raju Prabhakar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接