2013-10-31 38 views
1

我試圖點擊連接按鈕的「以人你可能知道」從LinkedIn頁面(http://www.linkedin.com/people/pymk?trk=nmp-pymk-new_pymk_title單擊特殊的按鈕與硒和Python

這個按鈕的HTML代碼是:

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

我tryed做到這一點:

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

,然後在列表中的每個元素調用函數點擊()。然而我不斷geting相同的錯誤:

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)' 

有人知道我在做什麼錯?

+2

你重複你的問題 - http://stackoverflow.com/questions/19716052/find-a-special-kind-of-buttons-with-selenium-and-python – furas

+0

聽起來像問題ISN元素不可見,或可見,但在某個其他元素背後。另外,我認爲LinkedIn的[用戶協議](http://www.linkedin.com/legal/user-agreement)有一些條款可能會禁止這種類型的爬蟲(ctrl + f for「scrape」)。 – rutter

+0

所以我無法做到這一點? – Findios

回答

2
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()