Unable to reproduce user behavior with selenium on Python
See original GitHub issue🐛 Bug Report
Hi.
I am trying to register a user in this practice site: http://practice.automationtesting.in/my-account/
The process is very simple, write a user-email, write a password and then click on register button.
As user, you manually do the steps before describe and you could register a user. but if you do with selenium, you can’t do it.
I discovered that manually you have a message about strong or weak password, and this message doesn’t appear with selenium. But there are more. If I use record and play process with selenium IDE, I can reproduce the user behave, as I show in the video.
I tried with Chrome and Firefox, but the result was the same.
So, I share technical information.
OS: Windows 10 x64
Python: 3.9.3
Pytest: 6.2.4
Selenium: 3.141.0
Chrome: 91.0.4472.77
Firefox: 89.0
Selenium IDE: 3.17.0
I also share the Python script:
import pytest
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
driver = None
def setup():
global driver
chrome_driver_path = #path to chrome driver
gecko_driver_path = #path to gecko driver
url = 'http://practice.automationtesting.in/my-account/'
browser = 'chrome'
if browser == 'chrome':
driver = webdriver.Chrome(executable_path=chrome_driver_path)
elif browser == 'firefox':
driver = webdriver.Firefox(executable_path=gecko_driver_path)
else:
raise ValueError('Invalid Browser')
driver.maximize_window()
driver.set_page_load_timeout(10)
driver.implicitly_wait(5)
try:
driver.get(url)
except TimeoutException:
print('Page not load')
driver.quit()
def test_register_user():
test_data = {
'username' : 'user_mail_test@gmail.com',
'password' : 'StR0nGp4AsSw0Rd'
}
driver.find_element_by_id('reg_email').send_keys(test_data['username'])
driver.find_element_by_id('reg_password').send_keys(test_data['password'])
wait_driver = WebDriverWait(driver,5,0.2)
try:
button = wait_driver.until(ec.element_to_be_clickable((By.NAME,'register')))
button.click()
except TimeoutException:
pytest.fail('Register button is not clickable')
def teardown():
driver.quit()
To execute the script I use:
python -m pytest path\to\script.py
What could be happening?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
💬 It looks like this is a question rather than an issue. 💡 A better way to address this is:
The issue lays on the website under test, if you check the page source, it is full of JS scripts at the end that need quite a while to load. Specifically, for password checks, this script is used. If the JS code has not loaded and you try to interact with the input fields, you won’t see the behaviour you are expecting.
JS code will take a while to load because every test executed with WebDriver it is using a fresh profile, where nothing has been cached. The IDE is using the current browser profile and session, which is why all that JS loads faster (cached).
I tried your script and I don’t think it has any issue, it is just that the page you want to test is taking too long to load. To evidentiate that, I added a “only for demo purposes” sleep, and then you can see how the code works well. If you want to keep learning on this website, I would suggest to contact the owners to improve the site’s performance and make it more testable, or to find a specific condition you can wait for before interacting with the website.
In the end, I believe this is not an issue with Selenium, rather with the website under test.
If you have any more questions, please join us at our IRC/Slack channel.