I'm automating with Selenium. I'm dealing with 2 variants (mobile, desktop) of a page. Both have a "Login" button, but the HTML is different.
First variant:
<div role="button"><div ...><span><span>Foo Bar MaybeQuux</span></span></div></div>
Second variant:
<a href="p/q/r" data="loginButton"><div><span><span>Foo Bar MaybeQuux</span></span></div></a>
I've written MaybeQuux
as for small screens it turns into Mayb...
. However Bar
is guaranteed.
Here's my code so far:
def waitClickable(by, text, timeout=60):
return WebDriverWait(driver, timeout).until(
EC.element_to_be_clickable(
(by, text)
)
)
waitClickable(By.XPATH, "???").click()
So my question is, would it possible to write a single xpath that can locate both variants?
If so I can avoid the awkwardness of having to wait on an object of unknown form.
ref: Python selenium : Explicitly wait for one of two elements to be loaded