Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

python - Logic Operators in WebDriverWait Expected Conditions

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>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...