2017-10-11 101 views
0

我需要瀏覽頁面左側here頁面左側的多個頁面。首先,我需要向下滾動特定的div部分,然後單擊next按鈕。但滾動在一種情況下完美(url_ok),並且在另一種情況下不起作用(url_trouble)。沒有任何想法爲什麼。 我測試的代碼:硒蟒蛇:如何滾動div

from selenium import webdriver 
import time 
driverPath = "C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe" 
driver = webdriver.Chrome(driverPath) 

url_trouble = 'https://2gis.ru/moscow/search/%D0%BF%D0%B0%D1%80%D0%BA%D0%BE%D0%B2%D0%BA%D0%B0%20/tab/geo?queryState=center%2F37.644653%2C55.827709%2Fzoom%2F12' 

url_ok = 'https://2gis.ru/moscow/search/%D0%BF%D0%B0%D1%80%D0%BA%D0%BE%D0%B2%D0%BA%D0%B0%20/tab/firms?queryState=center%2F37.644653%2C55.827805%2Fzoom%2F12' 


def click(url, driver): 
    driver.get(url) 
    driver.maximize_window() 
    time.sleep(5) 
    next_link_data = driver.find_element_by_css_selector("div.pagination__arrow._right") 
    next_link_data.location_once_scrolled_into_view 
    next_link_data.click() 

click(url_trouble, driver) # it doesn't work 
click(url_ok, driver) # it works 

所以現在的問題是如何滾動url_trouble的底部?

非常感謝您的提前!

回答

0

因爲我猜兩個「div.pagination__arrow._right」在頁面中。

使用更具體的選擇
嘗試這一個 - >「#模塊1-13-1-1-2-2> div.pagination__arrow._right」

driver.find_element_by_css_selector("#module-1-13-1-1-2-2 > div.pagination__arrow._right") 
+0

謝謝@DexJ,它的作品完美! – Vlad

+0

歡迎@Vlad – DexJ