4

I'm using Python / Selenium to submit a form then I have the web driver waiting for the next page to load by using an expected condition using class id.

My problem is that there are two pages that can be displayed but they do not share an unique element (that I can find) that is not in the original page. One page has a unique class is of mobile_txt_holder and the other possible page has a class id of notfoundcopy. I would like to use a wait that is looking for mobile_txt_holder OR notfoundcopy to appear.

Is it possible to combine two expected conditions into one wait?

Basic idea of what I am looking for but obviously won't work:

WebDriverWait(driver, 30).until(EC.presence_of_element_located(
    (By.CLASS_NAME, "mobile_txt_holder")))
    or .until(EC.presence_of_element_located((By.CLASS_NAME, "notfoundcopy")))

I really just need to program to wait until the next page loads so that I can parse the source.

Sample HTML:

<p class="notfoundcopy">Unfortunately, the number you entered is not in our tracking system.</p>

Guy
  • 46,488
  • 10
  • 44
  • 88
Aiden
  • 309
  • 2
  • 16
  • Possible duplicate of [CSS Selector "(A or B) and C"?](https://stackoverflow.com/questions/7517429/css-selector-a-or-b-and-c) – JeffC Sep 11 '17 at 03:24
  • @JeffC I'm new to Python so perhaps I am wrong, but I am looking for a Python specific answer. I believe the link you provided is just just for CSS and not for Python to be used to search CSS. – Aiden Sep 11 '17 at 03:37
  • With Python and Selenium you can use a CSS selector to locate an element. You can create a CSS selector, examples in the link, that uses OR logic so you can get what you want. – JeffC Sep 11 '17 at 03:38
  • @JeffC Oh sorry I didn't understand what you were getting at. I see DebanjanB's solution which I can now see you were getting at. Thanks for the help! – Aiden Sep 11 '17 at 03:46

1 Answers1

3

Apart from clubbing up 2 expected_conditions through or clause, we can easily construct a CSS to take care of our requirement The following CSS will look either for the EC either in mobile_txt_holder class or in notfoundcopy class:

element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, ".mobile_txt_holder, .notfoundcopy"))

You can find a detailed discussion in selenium two xpath tests in one

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thanks! I didn't understand what @JeffC was trying to tell me. I will try this out in the morning and post back. It now makes sense in my head. Let's see if I can translate that to code tomorrow. – Aiden Sep 11 '17 at 03:47
  • It's better to not answer a question that is a duplicate. It just clogs up the site with more of the same question that can be answered with the duplicate link already posted. – JeffC Sep 11 '17 at 03:47