I am working with this website: https://www.offerte.smartpaws.de/
Using selenium, I scraped through the first page, and did a click to go to the next section with very simple buttons, however, after continuing to the second page I get a timout exception while trying to click on the first button (gender).
Below is the code I used for going to the next page:
#click button to go to next page
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="button_get_quote"]'))).click()
time.sleep(2)
#loop though genders
for gender in ["male","female"]:
if gender == "male":
#click on male button
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="dog_form_s"]/div/div[1]/div/div/input[1]'))).click()
else:
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable(
(By.XPATH, '//*[@id="dog_form_g"]/div/div[1]/div/div/input[2]'))).click()
I have tried using try:
in case it was just taking long and added a time.sleep()
for the same reason, but still get a timeout error.
Do you guys know of any tricks to fix this or perhaps why it is happening, I thought it might be that I have to redifine the drive.get()
to the new page, but nothing.
Thanks
CodePudding user response:
I can not see elements matching //*[@id="dog_form_s"]/div/div[1]/div/div/input[1]
locator on the second page there.
The same about //*[@id="dog_form_g"]/div/div[1]/div/div/input[2]
XPath.
In order to select Male pet gender you can use this XPath: //input[@value='male ']
and correspondingly //input[@value='female']
to select Female pet gender.