Python Scraping - Selenium - Element is not clickable at point -


i'm trying click next button on webpage multiple times, need scrape page after each click. following code shortened illustrates situation. able scrape required tag after first click, second click fails. here code

from selenium import webdriver   selenium.common.exceptions import nosuchelementexception   selenium.webdriver.common.keys import keys    browser = webdriver.firefox()   browser.get('http://www.agoda.com/the-coast-resort-koh-phangan/hotel/koh-phangan-th.html')  browser.find_element_by_xpath("//a[@id='next-page']").click() browser.find_element_by_xpath("//a[@id='next-page']").click()  browser.quit() 

i error

webdriverexception: message: element not clickable @ point 

although when use beautifulsoup , source code after first click element trying click again there click.

i've read on other answers might need wait time not sure how implement that.

the first time click next page starts load, can't click on link on page still loading or on link on page replaced page! message quite correct. have wait next page appear before can click on next link. can sleep n seconds or, better, wait element appear before clicking on again.

have at: expected conditions

so there want use element_to_be_clickable on each attempt click. happens waits n seconds clickable , if not take state in time throws exception.

here blog post on this: how selenium wait page load after click

here simple example of how can use that. here have clicked on link first time, , after wait next load can:

    xpath = "//a[@id='next-page']"     webdriverwait(browser.webdriver, 10).until(         expected_conditions.element_to_be_clickable((by.xpath, xpath)))     browser.find_element_by_xpath(xpath).click() 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -