1

I have a url login script that was working fine for a few days but then quit, that used the chromium webdriver

driver = webdriver.Chrome('/snap/bin/chromium.chromedriver', options=option)

I can access the URL using Firefox or Chromium without my script (just normal). Or Firefox in a script. But using Chromium in a script, it clicks the login button and just hangs, that eventually leads to a timeout

selenium.common.exceptions.TimeoutException: Message:

If I open a new tab and try to login without the script but manually, it still hangs. A login is impossible (on my target site) within a launched browser from selenium, only.

#!/usr/bin/python3
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from seleniumbase import BaseCase
import time
import random

user_name = 'user'
password = 'password'
list = [
        ]
minptime = 4
maxptime = 24

list_length = len(list)
print('Array length ', list_length)
class MyMeClass(BaseCase):
        def method_a():
                option = webdriver.ChromeOptions()
                option.add_argument('--disable-notifications')
                option.add_argument("--mute-audio")
                driver = webdriver.Chrome('/snap/bin/chromium.chromedriver', options=option)

                driver.get("https://me.com/")
                print(driver.title)
                element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.login-btn.btn-shadow#login-fake-btn[data-testid='login-fake-btn']"))).click()
                driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/form/input[1]').send_keys(user_name)
                driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/form/input[2]').send_keys(password)
                time.sleep(5)
                driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/form/button').click() #button click in question
                time.sleep(8)
                driver.get(url)
                print(driver.current_url)
                return driver
driver = MyMeClass.method_a()

button I am accessing

enter image description here

How do I use/unblock the use of this login button in chromium in a script?

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
brad
  • 870
  • 2
  • 13
  • 38

1 Answers1

2

Try below code:

with contains

wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Log in')]"))).click()

Class Name

wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn-login btn-shadow']"))).click()

Note : please add below imports to your solution

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

Working Solution:

driver.get(" your url ")
wait = WebDriverWait(driver,30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='login-fake-btn']")))
print element.text
element.click()

wait = WebDriverWait(driver,30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='email']"))).send_keys("Test")
wait = WebDriverWait(driver,30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='password']"))).send_keys("Test")
element1 = wait.until(EC.presence_of_element_located((By.XPATH, "//div[@id='login-overlay']//div//form//button")))
element1.click()

output :

enter image description here

SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
  • I tried both. Both found the button and pressed it, but no login occurred. Same as before. – brad Jul 28 '20 at 22:35
  • What error you are getting after clicking expected button? – SeleniumUser Jul 28 '20 at 22:56
  • The exact same timeout as in the post – brad Jul 29 '20 at 12:34
  • Can you please sharee your url ? I think your page is taking too long to load and because of that its throwing TimeoutException. – SeleniumUser Jul 29 '20 at 12:39
  • I can open 2 or more browsers at the same time an login to it fine. I can run a script using firefox and it logs in fine. I can use chromium without the script and login fine. But "using a script" in chromium hangs until it times out. Opening a second tab within the script launched browser also fails doing it manually. I have to shut the script down and close the browser before I can login. https://bpa.st/IEQQ – brad Jul 29 '20 at 12:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218823/discussion-between-seleniumuser002-and-brad). – SeleniumUser Jul 29 '20 at 13:29