selenium two xpath tests in one

后端 未结 1 1525
说谎
说谎 2020-12-04 03:48

I try to combine check for two scenarios:

If startupcheck fails we get a try again button:

el = WebDriverWait(self.driver, 10).until(
  EC.element_to         


        
相关标签:
1条回答
  • 2020-12-04 04:08

    You can club up combine check for both the elements using OR clause through a lambda expression as follows:

    el = WebDriverWait(driver, 20).until(lambda x: (x.find_element_by_name("Try again"), x.find_element_by_xpath("//Custom/Edit")))
    

    An alternative solution will be:

    el = WebDriverWait(driver,20).until(lambda driver: driver.find_element(By.NAME,"Try again") and driver.find_element(By.XPATH,"//Custom/Edit"))
    

    As an alternative you can club up combine check for both the elements using the equivalent css-selectors as follows:

    el = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[name='Try again'], Custom>Edit")))
    

    References

    • Python / Selenium: Logic Operators in WebDriverWait Expected Conditions
    • How to extract dynamic text from multiple child nodes within the html through getText()
    0 讨论(0)
提交回复
热议问题