Harsh Vardhan
Harsh Vardhan

Reputation: 143

Not able to create dynamic xpaths in python selenium for this website

Here is the website which I'm trying to automate for scraping data: website link. I have to do the following:

  1. select Location as Victoria, then region as Melbourne.
  2. select Make as, say, Abarth. the will repeat for other makes.

I have tried static xpaths and also tried creating dynamic xpaths with my limited knowledge but still i am not able to do the task.

I use python selenium and automating google chrome.

Here is a snapshot of my wrong code for selection Abarth as make:

make_ele = WebDriverWait(driver,40).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-name="make"]'))).click()
select_abarth_ele = WebDriverWait(driver,40).until(EC.element_to_be_clickable((By.XPATH, '//div[@class="multiselect-searchbox"]//input[@class, "border py-1 px-2 mb-1")]'))).send_keys("Abarth")

Upvotes: 1

Views: 40

Answers (1)

WKOW
WKOW

Reputation: 366

Your xpaths has to be reviewed. Try this:

make_ele = WebDriverWait(driver,40).until(EC.element_to_be_clickable((By.XPATH, '//span[contains(text(),'Make')]'))).click()
select_abarth_ele = WebDriverWait(driver,40).until(EC.element_to_be_clickable((By.XPATH, '//div[contains(@class,"multiselect-searchbox")]/input'))).send_keys("Abarth")

If you don't want to use contains(text(),'text') you can use also following relative path //div[@data-name="make"]

Upvotes: 0

Related Questions