2016-05-29 2 views
0

セレンを使ってJavaScriptページをスクラップしようとしていて、何か問題が発生しています。クリックは別のページには移動しませんが、JavaScriptを使用して次の10件のレビューを表示します。Python Seleniumがハイパーリンクをクリックしても同じページに残ります

最初のクリックは機能しているようですが、2回目のクリックは機能しません。常に要素が存在しないと言っています。

使用してコードイムは

Page is ready! 
Page is ready! 
WebDriverException: Message: Element is not clickable at point 

これが機能しない理由任意のアイデアを、私はクリックする要素があることをチェックしています

from selenium import webdriver 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.common.exceptions import TimeoutException 
from selenium.webdriver.support import expected_conditions 
from selenium.webdriver.common.by import By 

browser = webdriver.Firefox() 
browser.get("http://www.agoda.com/the-coast-resort-koh-phangan/hotel/koh-phangan-th.html") 
delay = 3 # seconds 
xpath = "//a[@id='next-page']" 
try: 
    WebDriverWait(browser, delay).until(expected_conditions.element_to_be_clickable((By.XPATH, xpath))) 
    print "Page is ready!" 
except TimeoutException: 
print "Loading took too much time!" 

browser.find_element_by_xpath("//a[@id='next-page']").click() 

try: 
    WebDriverWait(browser, delay).until(expected_conditions.element_to_be_clickable((By.XPATH, xpath))) 
    print "Page is ready!" 
except TimeoutException: 
    print "Loading took too much time!" 

browser.find_element_by_xpath("//a[@id='next-page']").click() 

try: 
    WebDriverWait(browser, delay).until(expected_conditions.element_to_be_clickable((By.XPATH, xpath))) 
    print "Page is ready!" 
except TimeoutException: 
    print "Loading took too much time!" 

です。

私は理解していないことは、ページが準備が整っていると言います。そのため、クリックしようとしている要素が見つかっていますが、この要素をクリックしてクリックできません。

+0

セレンは、要素の途中でクリックしようとすると、何らかの理由でそれのために何らかの理由であなたの要素がクリック可能でないように見えます。それはクリックすることができ、クリック可能で、クリックしようとしている場所ではありません。 element_to_be_clickableは、要素が表示され有効になっているかどうかをチェックしますが、要素の中央がクリック可能かどうかを実際にチェックしません。おそらくページを少し下にスクロールして、矢印要素が完全に見えるようにしますか? – Mobrockers

+0

[this](https://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error)stackoverflowこの問題についての記事を参照してください。 – Mobrockers

答えて

-1

ここで私は、私はクロームのドライバを使用しているナビゲートしますその内のコードを配置します: あなたはここからダウンロードできます。Chrome Driver

from selenium import webdriver 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.common.exceptions import TimeoutException 
from selenium.webdriver.support import expected_conditions 
from selenium.webdriver.common.by import By 
import time 

browser = webdriver.Chrome("./chromedriver.exe") 
browser.get("http://www.agoda.com/the-coast-resort-koh-phangan/hotel/koh-phangan-th.html") 
delay = 3 # seconds 
xpath = "//a[@id='next-page']" 

try: 
    for i in range(0,5): 
     browser.find_element_by_id("next-page").click() 
     time.sleep(5) 
     print i 
except Exception as e: 
    print e 

time.sleep(5) 
browser.quit() 
関連する問題