Search code examples
selenium-webdriverxpath

Not able to use XPATH to interactive with the text filed in my special case


From the following picture, I am trying to clear the "Server Address" field, and to input a new value. but somehow, it keeps giving me timeout exception. enter image description here

here is my general python code. Any alternative ways I may try ?

  try:
        target = "//label[contains(text(), 'Server address')]/following-sibling::input"
        WebDriverWait(self.driver, 30).until(
            EC.presence_of_element_located((By.XPATH, target))).clear()
        WebDriverWait(self.driver, 30).until(
            EC.presence_of_element_located((By.XPATH, target))).send_keys(var)
    except Exception as e:
        ....

Thanks for the help.

Jack


Solution

  • I see that the XPath exists inside an iframe. There is a certain approach when handling iframes which your can read here. But in simple terms it means: You need to switch to the iframe which is seen as a seperate window by Selenium.

    1. Write an XPath for the ancestor iframe of the HTML element you try to interact
    2. Use the Selenium documentation according to the right language you use
    3. After succesfull switching to the iframe, you can now interact with the proper HTML element //label[contains(text(), 'Server address')]/following-sibling::input