1

I am trying to connect to the particular webpage but it does not click on Login button:

browser.get('https://www.tsago.gr/eshop/account')
print('Browser Opened')
username = browser.find_element_by_id('email')
username.send_keys(email)
password = browser.find_element_by_id('password')

password.send_keys(pwd)
time.sleep(2)
sing_in = browser.find_element_by_xpath('//*[@class="btn btn-primary"]')
sing_in.click()
print('Login Clicked')

I have tried find element by css, by name etc but I dont know why is not clicking on the button in order to login

The html part is the following

<div class="span3 float-right" style="float:right;">                                   
   <button type="submit" class="btn btn-primary">Connect</button>
</div>

The username and password are written and they are correct

2
  • Try sing_in = browser.find_element_by_xpath('//button[@type="submit"]') Commented Mar 24, 2019 at 21:50
  • No nothing.. is there a way to click Enter by code? instead by clicking button? maybe it needs focus? Commented Mar 24, 2019 at 21:55

3 Answers 3

1

Seems you were pretty close. Perhaps Cookies Message Bar was the obstacle and you can either accept the cookies or scroll the Connect button into view and you can use the following solution:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_argument("--disable-extensions")
    # options.add_argument('disable-infobars')
    browser = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    browser.get('https://www.tsago.gr/eshop/account')
    print('Browser Opened')
    WebDriverWait(browser, 30).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input#email[name='email']"))).send_keys("Nikos")
    browser.find_element_by_css_selector("input#password[name='password']").send_keys("Nikos")
    browser.execute_script("window.scrollBy(0,250)", "");
    browser.find_element_by_css_selector("div.control-group div.span3 button.btn.btn-primary").click()
    print('Login Clicked')
    
  • Console Output:

    Browser Opened
    Login Clicked
    
  • Browser Snapshot:

cookies

Sign up to request clarification or add additional context in comments.

Comments

0

The following css Selector should uniquely identify the button you are looking for:

driver.find_element_by_css_selector('div.span3.float-right > button')

Comments

0

this is working for me:

driver.find_element_by_css_selector('div.span3 > button[type="submit"]').click()

generally, you should make sure you identify the correct element before coding. to do so - use devTools (f12 on chrome/firefox), and run your query in the 'console' tab

for xpath identification try $x, i.e: $x('//button[@type="submit"]').

for css selector use $$ like so : $$("div.someClass#someID")

you can than hover over the results and the found elements would highlight

edit: i noticed you had trouble with the css option, you can allso try

driver.find_element_by_xpath('//div[contains(@class,"span3")]/button[contains(@class,"btn-primary")]")

Comments

Your Answer

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