1

I am currently trying to automate the input into a form on a website, but i cant seem to find a way to select the dropdown.

On website:

immosuche.degewo.de/de/properties/W1400-40660-0750-0902.html

You'll need to click on Kontaktieren.

In HTML:

I'm currently trying to find it by xpath this way:

driver.findElement(By.xpath("/html/body/el-root/div/el-listing-application/form/div[2]/div[1]/nz-form-item/nz-form-control/div/span/nz-select/div")).click();

But i always get this exception:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/el-root/div/el-listing-application/form/div[2]/div[1]/nz-form-item/nz-form-control/div/span/nz-select/div"}
  (Session info: chrome=108.0.5359.126)
For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element

Does any one have any idea how i could click it without getting the Exeption?

Prophet
  • 32,350
  • 22
  • 54
  • 79
josh.12
  • 21
  • 6

2 Answers2

1

The <nz-select> element is within an iframe so you have to:

  • Induce WebDriverWait for the frameToBeAvailableAndSwitchToIt.

  • Induce WebDriverWait for the desired elementToBeClickable.

  • You can use the following locator strategies:

    driver.get("https://immosuche.degewo.de/de/properties/W1400-40660-0750-0902.html");
    new WebDriverWait(driver, Duration.ofSeconds(10), Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button#cookie-consent-submit"))).click();
    new WebDriverWait(driver, Duration.ofSeconds(10), Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//p[contains(., 'degewo Marzahner Wohnungsgesellschaft mbH')]//following::div[1]//span[text()='Kontaktieren']"))).click();
    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[src^='https://app.wohnungshelden.de/public/listings']")));
    WebElement elem = new WebDriverWait(driver, Duration.ofSeconds(10), Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//nz-select[@nzplaceholder='Bitte auswählen']//div[@nz-select-top-control]")));
    ((JavascriptExecutor)driver).executeScript("arguments[0].click();", elem);
    
  • Browser Snapshot:

kontakt

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

Those elements are inside an iframe. To access elements inside it you need to switch into that iframe first.
The following code sample is working:

import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)

url = "https://immosuche.degewo.de/de/properties/W1400-40660-0750-0902.html"
driver.get(url)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".expose__header-functions a[href='#kontakt']"))).click()
time.sleep(3)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.TAG_NAME, "iframe")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[formcontrolname='salutation']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//li[contains(.,'Herr')]"))).click()
wait.until(EC.element_to_be_clickable((By.ID, "firstName"))).send_keys('Prophet')
wait.until(EC.element_to_be_clickable((By.ID, "lastName"))).send_keys('Mozes')
wait.until(EC.element_to_be_clickable((By.ID, "email"))).send_keys('mymail@mail.com')
wait.until(EC.element_to_be_clickable((By.ID, "formly_2_input_numberPersonsTotal_0"))).send_keys('5')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".form-actions [type='submit']"))).click()

The result screenshot is:

enter image description here

The request is sent.
When finished working inside the iframe don't forget to switch to the default content with:

driver.switch_to.default_content()
Prophet
  • 32,350
  • 22
  • 54
  • 79