Click Hidden Button Wrapped inside div via Selenium in Python

357 views Asked by At

I am automating login on Workday portal using Chrome webDriver in selenium, how do I click on the hidden sign-in button, which is defined as:

<div class="css-1s1r74k">
    <div font-size="14" height="40" aria-label="Sign In" role="button" tabindex="0" data-automation-id="click_filter"
        class="css-1n9xe37">
    </div>
    <button type="submit" data-automation-id="signInSubmitButton" font-size="14" height="40" class="css-a9u6na" tabindex="-2" aria-hidden="true">Sign In</button>
</div>

Here's the code I am using, but it is not able to perform the click action on the specific button:

    signInButton = driver.find_element(By.XPATH,'//*[@id="wd-Authentication-NO_METADATA_ID-uid6"]/div/div[1]/div/form/div[3]/div/div/div/div/button')
    driver.execute_script("arguments[0].click();", signInButton)

Here's the login page sample - https://wd1.myworkdaysite.com/en-US/recruiting/snapchat/snap/login

2

There are 2 answers

0
JeffC On

The BUTTON isn't hidden. You can see the "Sign In" text on the button from the HTML you provided. I'm not sure why your code doesn't work, it's possible you need to add a wait. I updated the locator to a CSS selector because they are better supported and that XPath you are using is brittle since it has so many levels, indices, etc.

from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-automation-id='signInSubmitButton']"))).click()
0
KunduK On

Basically if you see the Html,

<div class="css-1s1r74k">
    <div font-size="14" height="40" aria-label="Sign In" role="button" tabindex="0" data-automation-id="click_filter"
        class="css-1n9xe37">
    </div>
    <button type="submit" data-automation-id="signInSubmitButton" font-size="14" height="40" class="css-a9u6na" tabindex="-2" aria-hidden="true">Sign In</button>
</div>

div element has a role attribute button and which is clickable.

Try following code to click on the Sign In Button.

driver.get("https://wd1.myworkdaysite.com/en-US/recruiting/snapchat/snap/login")
signInButton =WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "div[aria-label='Sign In']")))
signInButton.location_once_scrolled_into_view # scroll to the element
time.sleep(1) #wait for a second
driver.execute_script("arguments[0].click();", signInButton)

you need following imports

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time

Browser snapshot:

enter image description here