python - 用 selenium 和 python 单击特殊按钮

标签 python css button selenium click

我正在尝试单击 linkedin 中“您可能认识的人”页面上的连接按钮 (http://www.linkedin.com/people/pymk?trk=nmp-pymk-new_pymk_title)

这个按钮的html代码是:

<a class="vcard-button bt-connect bt-primary" href="#"><span>&nbsp;</span>Connect</a>

我试着这样做:

buttons=driver.find_elements_by_css_selector("a[class='vcard-button bt-connect bt-primary']") 

然后为列表的每个元素调用函数 click()。但是我不断收到同样的错误:

selenium.common.exceptions.WebDriverException: Message: u'unknown error: Element is not clickable at point (473, 14). Other element would receive the click: <input name="keywords" id="main-search-box" class="search-term" type="text" value="" autocomplete="off" placeholder="Search for people, jobs, companies, and more...">
(Session info: chrome=30.0.1599.101)
(Driver info: chromedriver=2.2,platform=Windows NT 6.1 SP1 x86_64)'

有人知道我做错了什么吗?

最佳答案

from selenium.webdriver.common.action_chains import ActionChains
self.driver = webdriver.Firefox()
# You need a mouse to hover the span elements here
self.mouse = webdriver.ActionChains(self.driver)    

# You need get the element from its xpath:
buttons=driver.find_elements_by_css_selector("a[class='vcard-button bt-connect bt-primary']")

# Then you hover on span element by mouse and click on it:
self.mouse.move_to_element(buttons).click().perform()

关于python - 用 selenium 和 python 单击特殊按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19717943/

相关文章:

javascript - 从外部 div 单击时的 Jquery 和 Javascript 滚动图像

HTML 按钮 : Navigate to Other Page - Different Approaches

c# - 检查窗体上的按钮单击事件 - C#

python - python中多个列表的高效排列

python - 在 Postgres 上使用 sqlalchemy 创建部分唯一索引

html - Div 内容在多部分表单上重叠

html - 为什么父div与 child 的高度不一样?

python - Pandas 返回空的DataFrame,空的列和空的索引

python - flask jsonify : how to escape characters

android - 如何在 Google android 应用程序后退按钮上做按钮点击动画?