Home > front end >  Selenium -xpath creating
Selenium -xpath creating

Time:11-24

I'm struggling with finding the xpath for the "Next" button that I need in order to automate the scrapping process...

Just in case it's the rel = "next" one.

driver = webdriver.Safari()
driver.get('https://autoplius.lt/skelbimai/naudoti-automobiliai?make_id=43&model_id=186&make_date_from=1999&make_date_to=2005')
cookie = driver.find_element_by_xpath('//*[@id="onetrust-accept-btn-handler"]')
cookie.click()

Next = driver.find_element_by_xpath('//li[text()="Kitas"]/a')
Next.click()

enter image description here

CodePudding user response:

The xapth //li[text()="Kitas"]/a is not highlighting any element in the DOM. You can refer this link to find unique locators.

You can use below locators for Next button.

Xpath:

//div[@class='page-navigation-container']//a[@class='next']

CSS Selector:

div.page-navigation-container a.next
# Imports Required for Explicit wait

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver.get("https://autoplius.lt/skelbimai/naudoti-automobiliai?make_id=43&model_id=186&make_date_from=1999&make_date_to=2005")

wait = WebDriverWait(driver,30)

wait.until(EC.element_to_be_clickable((By.ID,"onetrust-accept-btn-handler"))).click()

next_button = driver.find_element(By.XPATH,"//div[@class='page-navigation-container']//a[@class='next']")
next_button.click()

CodePudding user response:

You should be able to right click on the element in the inspection tool. Once you right click, hover on copy and click 'Copy XPath'. I have attached a screenshot of the process. Let me know how it goes!

Copy XPath

  • Related