【问题标题】:Clicking special button with selenium and python使用 selenium 和 python 单击特殊按钮
【发布时间】:2013-11-12 03:11:57
【问题描述】:

我正在尝试单击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)'

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

【问题讨论】:

  • 听起来有问题的元素不可见,或者可见但在其他元素后面。另外,我认为 LinkedIn 的 user agreement 有一些条款可能会禁止这种机器人爬行(ctrl+f 表示“scrape”)。
  • 所以我没有办法做到这一点?
  • 清理你的css选择器——改用a.vcard-button.bt-connect.bt-primary
  • 它在第一种情况下有效,但随后停止工作:/

标签: python css button selenium click


【解决方案1】:
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()

【讨论】:

    猜你喜欢
    • 2021-04-07
    • 2018-08-22
    • 2021-03-31
    • 2021-01-31
    • 2020-08-06
    • 2017-04-22
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多