[Python] python/selenium (pytest) automation, I have 2 different path for date function and I...

Discussão em 'Python' iniciado por Stack, Junho 22, 2025.

  1. Stack

    Stack Membro Participativo

    I want to use two XPaths defined in different .py files in select_start_date(). In one .py file I have select_start_date() that uses the first XPath but now I want to use a second XPath defined in a different .py file in the same method.

    start_date_field_xpath="//input[@placeholder='Start date']"
    select_date_xpath = "//input[@placeholder='Choose a date']"

    def select_start_date(self):
    try:
    wait = WebDriverWait(self.driver, 80)
    wait.until(EC.visibility_of_element_located((By.XPATH, self.start_date_field_xpath)))
    element = self.driver.find_element(By.XPATH, self.start_date_field_xpath)
    date = datetime.date.today() + datetime.timedelta(days=1)
    str_date = str(date).split("-")
    start_date = ''.join(str(x) for x in str_date)
    element.send_keys(start_date)
    time.sleep(2)
    ActionChains(self.driver).send_keys(Keys.ESCAPE).perform()
    self.logger.info("selected start date")

    except Exception as e:
    self.logger.info("could not select start date")
    assert False

    Continue reading...

Compartilhe esta Página