0

I want to automate my opening session so, following some tutorials and other questions on Stackoverflow, I did the following :

import selenium  

from selenium import webdriver

driver = webdriver.Safari()


driver.get('https://www.codeur.com/users/sign_in')


id_box = driver.find_element_by_name('user_email')

id_box.send_keys(my_mail)

# Find password box
pass_box = driver.find_element_by_name('user_password')
# Send password
pass_box.send_keys(my_password)
# Find login button
login_button = driver.find_element_by_name('commit')
# Click login
login_button.click()

I get the following error :

line 321, in execute
    self.error_handler.check_response(response)
line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: 


Process finished with exit code 1

Is it because I missed the right name to the submit button?

The html corresponding, I think, would be :

<span class="recaptcha-button-enabled">
<input type="submit" name="commit" value="Se connecter" class="btn btn-primary btn-lg btn-block" data-disable-with="Se connecter">
</span>
<span class="recaptcha-button-disabled" style="display: none">
<input type="submit" name="commit" value="Connexion en cours…" class="btn btn-primary btn-lg btn-block" disabled="disabled" data-disable-with="Connexion en cours…">
</span>

4 Answers 4

1

There is an overlapping element on the Submit button, so you can click on that element using its xpath and for user name and password fields, you should use id to fetch the element instead of name.

Your code should be like:

import selenium  

from selenium import webdriver

driver = webdriver.Safari()


driver.get('https://www.codeur.com/users/sign_in')


id_box = driver.find_element_by_id("user_email")

id_box.send_keys(my_mail)

# Find password box
pass_box = driver.find_element_by_id("user_password")
# Send password
pass_box.send_keys(my_password)
# Find login button
login_button = driver.find_element_by_xpath("//span[@class='recaptcha-button-enabled']")
# Click login
login_button.click()

However, there is a captcha getting displayed after clicking on Submit button on the page so I don't think you would be able to proceed with the automation.

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

2 Comments

Regarding the captcha, since my browser is supposed to remember me, when I log in manually the captcha is never asked, so I hoped that, using that very browser, he could let me pass with selenium without captcha (which is not the case apparently ) : would you have a explanation to that?
@Netchaiev Nope it doesnt work like that because selenium starts a new browser everytime and that browser doesnt store any of your previous information or cache or passwords. And there is mechanism to detect that if the element is getting clicked through a bot or manually, so whenever it is clicked through a bot, a captcha appears and you cannot break that captcha through automation.
1

The submit button Se connecter is overlapped by a notification. You can Scroll up the element inducing WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://www.codeur.com/users/sign_in')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#user_email"))).send_keys("[email protected]")
    driver.find_element_by_css_selector("input#user_password").send_keys("Netchaiev")
    driver.execute_script("return arguments[0].scrollIntoView(true);", driver.find_element_by_css_selector("input[value='Se connecter']"))
    driver.find_element_by_css_selector("input[value='Se connecter']").click()
    
  • Using XPATH:

    driver.get('https://www.codeur.com/users/sign_in')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='user_email']"))).send_keys("[email protected]")
    driver.find_element_by_xpath("//input[@id='user_password']").send_keys("Netchaiev")
    driver.execute_script("return arguments[0].scrollIntoView(true);", driver.find_element_by_xpath("//input[@value='Se connecter']"))
    driver.find_element_by_xpath("//input[@value='Se connecter']").click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

codeur

Comments

0

Use like name:

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

element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "commit")))

element.click();

1 Comment

I replaced 'login_button' in my code by 'element = ...' from your code (+ 'element.click()', of course), but got pretty much the same response error :(
0

Finally the code is working better if I replace both "find_element_by_name" by "find_element_by_id" ; but within Safari, it won't seem to click. I instead used Chrome(), but in that case I needed to download 'chromedriver' and indicate the path where it is :

driver = webdriver.Chrome(executable_path='path_to_the_folder_where_chromedriver_is/chromedriver')

And then it worked fine (but the website ask then to fulfill a Captcha, so I guess it is kinda the end of the road for automation...)

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.