0

I am trying to automate login process to a website. There are no issues with finding the first element:

driver.find_element(By.ID, 'topbar-cta-btn').click()

After clicking the first element, a new page loads. On a new page there is a different button that Selenium cannot locate.

Here is a full code:

from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

chrome_options = Options()
s = Service(r"somepath")
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument("--incognito")

login = "login"
pwd = "password"

def run():
    driver = webdriver.Chrome(service=s, options=chrome_options)
    driver.get("https://www.zalando-lounge.pl/")
    driver.find_element(By.ID, 'topbar-cta-btn').click()   # 1st button - works fine
    driver.find_element(By.ID, 'sso-login-lounge').click()   # 2nd button - the issue occurs
    driver.find_element(By.ID, 'form-email').send_keys(login)
    driver.find_element(By.ID, 'form-password').send_keys(pwd)
    driver.find_element(By.ID, 'login-form-submit').click()

run()

The interesting thing is, when you inspect button for the first time, it opens with highlighted wrapped body:

<body class="is-uc is-uc_lounge no-scroll" style=""><div id="lightningjs-usabilla_live" style="display: none;"><div><iframe frameborder="0" id="lightningjs-frame-usabilla_live"></iframe></div></div>

inspecting second time:

    <button color="dark" type="button" aria-labelledby="sso-login-lounge" class="Wrapper-sc-8so8sv eyQKCA"><span id="sso-login-lounge" class="Label-sc-5suzw6 foNedc"><i class="LoginButtonWrapperstyles__IconWrapper-hp__sc-18llv3w-1 fVoPeM"><svg color="#FFFFFF" width="24px" height="24px" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false" class="SvgIcon-sc-1sexdd6 lhpNNK"><path fill-rule="evenodd" clip-rule="evenodd" d="M4 4.75h16A2.25 2.25 0 0 1 22.25 7v10A2.25 2.25 0 0 1 20 19.25H4A2.25 2.25 0 0 1 1.75 17V7A2.25 2.25 0 0 1 4 4.75zM3 7c0-.063.006-.126.017-.186L9.5 12l-6.482 5.186A1.006 1.006 0 0 1 3 17V7zm1 11h16l-6.5-5.2-.485.388a1.625 1.625 0 0 1-2.03 0L10.5 12.8 4 18zm6.902-6.48.864.692c.137.11.331.11.468 0l.865-.692a.706.706 0 0 1 .022-.017L20 6H4l6.878 5.502a.593.593 0 0 1 .024.019zM14.5 12l6.482 5.186c.011-.06.017-.122.017-.186V7c0-.063-.006-.126-.017-.186L14.5 12z" fill="inherit"></path></svg></i><span>Zaloguj się</span></span></button>

Is there something built in the page that prevents locating the second button?

2
  • Can you put a little time gap between 1st and 2nd click and then try again? like time.sleep(2). Commented Jun 20, 2022 at 10:01
  • @UserAG Already tried it before, but it didn't work For some reason it works now... Well, thanks! Commented Jun 20, 2022 at 10:09

2 Answers 2

1

Try the below to click on the button

driver.find_element(By.XPATH, "//button[@aria-labelledby='sso-login-lounge']").click()

OR

driver.find_element(By.XPATH, "//button[contains(@class,'Wrapper-sc-8so8sv eyQKCA')]").click()

OR

element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(@aria-labelledby,'sso-login-lounge')]")))

element.click();

Do not forget to import the below

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

1 Comment

Works as well, thanks! I implemented this to other elements. This way seems to be way more reliable and efficient than sleep(). However, it looks like the page is blocking the Selenium now and doesn't allow me to log in using the script, but I guess it's a different topic.
0

As suggested by @UserAG putting sleep() between each search did the trick.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.