Issue
I am trying to build scraper for a house rent website, but I'm failing on move to next page. And show the follow error:
line 44, in <module> browser.find_element_by_xpath("//div[@class='pagination_hi']/[rel='next']").click()
And this is elements within which the pagination numbers are:
<div class="pagination_hi">
previous_page
</div><div class="pagination_hi">
<a href="https://www.28hse.com/rent/page-2" rel="next">next_page</a>
Solution
There are 4 ways to click in Selenium.
I will use this xpath
//a[text()='next_page']
Code trial 1 :
time.sleep(5)
browser.find_element_by_xpath("//a[text()='next_page']").click()
Code trial 2 :
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='next_page']"))).click()
Code trial 3 :
time.sleep(5)
button = browser.find_element_by_xpath("//a[text()='next_page']")
browser.execute_script("arguments[0].click();", button)
Code trial 4 :
time.sleep(5)
button = browser.find_element_by_xpath("//a[text()='next_page']")
ActionChains(browser).move_to_element(button).click().perform()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.