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>
CodePudding user response:
Correct XPath syntax should be
//div[@class='pagination_hi']/a[@rel='next']
You can also try to locate node by link text:
browser.find_element_by_link_text("next_page").click()
CodePudding user response:
There are 4 ways to click in Selenium.
I will use this xpath
//a[text()='next_page']
Code trial 1 :
time.sleep(5)
driver.find_element_by_xpath("//a[text()='next_page']").click()
Code trial 2 :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='next_page']"))).click()
Code trial 3 :
time.sleep(5)
button = driver.find_element_by_xpath("//a[text()='next_page']")
driver.execute_script("arguments[0].click();", button)
Code trial 4 :
time.sleep(5)
button = driver.find_element_by_xpath("//a[text()='next_page']")
ActionChains(driver).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