Alex
Alex

Reputation: 44405

How to fix 'obscured' error in selenium?

On a non-public webpage I have the following html content:

<span click.delegate="placeCurrentInjection()" style="display:flex" class="au-target" au-target-id="611"> 
<ui-button glyph="glyph-iclamp" small="" primary="" disabled.bind="currentPlaceDisabled" 
style="width: auto; max-width: 20em;" class="au-target ui-small ui-button primary" au-target-id="612" role="button" data-value="">
    <span class="ui-indicator"><!--anchor--></span>
    <ui-glyph glyph.bind="glyph" class="au-target ui-icon ui-btn-icon glyph-iclamp" au-target-id="36"><!--view-->
    <svg>
      <use tabindex="-1" x="0" y="0" class="au-target" 
      au-target-id="11" xlink:href="#glyph-iclamp"></use>
    </svg>
    <!--anchor--></ui-glyph><!--anchor-->
    <!--anchor-->
    <span class="ui-label">Place current injection<!--slot--></span>
    <!--anchor--></ui-button> </span>

which shows a button like follows:

enter image description here

and I want to click on that button, using the following code in selenium 3.8.0:

elem = WebDriverWait(self.webdriver, time_sec).\
                until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(), 'Place current injection')]")))
elem.click()

However, I get the following error:

E       ElementClickInterceptedException: Message: Element <span class="ui-label"> is not clickable at point (782.2999877929688,156.03334045410156) because another element <ui-button class="au-target ui-small ui-button primary"> obscures it

Despite the fact the actual text is not obscured in any way and I can click on it - how to fix this issue?

Upvotes: 0

Views: 1617

Answers (1)

Guy
Guy

Reputation: 50949

The element you located is just the text on a label of the button. You need to click on the button itself, which is actually the element from the error message you received. The button is the parent element so you can use the text to locate it by moving to the parent

(By.XPATH, "//span[contains(text(), 'Place current injection')]/..")

Upvotes: 1

Related Questions