raul
raul

Reputation: 1269

Python Selenium unable to click on button (not inside iframe)

There's a button on the webpage that looks like this:

<button class="WAXG WEXG WKKH WOWG WPO" tabindex="0" data-automation-activebutton="true" aria-hidden="false" aria-disabled="false" data-automation-id="wd-ActiveList-addButton" role="button" data-automation-button-type="AUXILIARY" title="Add" type="button"><span class="WFXG WBXG"></span><span class="WCXG" title="Add">Add</span></button>

I use the following code to click on the button:

xpath = "//button[@data-automation-id='wd-ActiveList-addButton']"
add = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, xpath)))
add.click()

It always results in the following error:

selenium.common.exceptions.TimeoutException: Message:

I have tried using different ways to find the element and click, but always get the same error. The button is not inside an iframe. Moreover, I'm able to access/click on all elements around the button. As the error message is empty, I'm clueless as to why this happens.

EDIT

Here's some surrounding code from the inspector:

<div class="WF-M WFN WOYM WEYM" id="wd-SectionView-NO_METADATA_ID">
    <div class="WH-M">
        <div class="WOO WFN" data-automation-id="activeList" id="wd-ActiveList-  6$87772">
            <div class="WHP">
            </div>
            <button class="WAXG WEXG WKKH WOWG WPO" tabindex="0" data-automation-activebutton="true" aria-hidden="false" aria-disabled="false" data-automation-id="wd-ActiveList-addButton" role="button" data-automation-button-type="AUXILIARY" title="Add" type="button">
                <span class="WFXG WBXG"></span>
                <span class="WCXG" title="Add">Add</span>
            </button>
        </div>
    </div>
</div>

Upvotes: 1

Views: 408

Answers (1)

Andersson
Andersson

Reputation: 52665

As I've already assumed in comments there are two buttons on page that can be found by attribute data-auto‌​mation-id='wd-Active‌​List-addButton': the first is hidden. That's why your expectation to wait until it become visible always returns False

You might need to use below code:

xpath = "(//button[@data-automation-id='wd-ActiveList-addButton'])[2]"
add = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, xpath)))
add.click()

It should allow you to click visible "Add" button

Upvotes: 1

Related Questions