0

I'm trying to log in to http://sports.williamhill.com/bet/en-gb using python and selenium.

Here is what I've tried so far:

from selenium import webdriver session = webdriver.Chrome() session.get('https://sports.williamhill.com/bet/en-gb') # REMOVE POP-UP timezone_popup_ok_button = session.find_element_by_xpath('//a[@id="yesBtn"]') timezone_popup_ok_button.click() # FILL OUT FORMS usr_field = session.find_element_by_xpath('//input[@value="Username"]') usr_field.clear() WebDriverWait(session, 10).until(EC.visibility_of(usr_field)) usr_field.send_keys('myUsername') pwd_field = session.find_element_by_xpath('//input[@value="Password"]') pwd_field.clear() pwd_field.send_keys('myPassword') login_button = session.find_element_by_xpath('//input[@id="signInBtn"]') login_button.click() 

I'm getting the following error.

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible 

when trying to execute

usr_field.send_keys('myUsername') 

The usr_field element seems to be visible if I'm viewing it with the inspector tool, however I'm not 100% sure here.

I'm using this script (with some modifications) successfully on other sites, but this one is giving me a real headache and I can't seem to find the answer anywhere on the net.

Would appreciate if someone could help me out here!

6
  • step one: start a debugger and find out which element is not visible Commented Oct 4, 2017 at 16:17
  • Put some sleep to leave the time for the elements ti be loaded. Commented Oct 4, 2017 at 16:20
  • @SamirSadek Don't use sleeps... sleeps are a bad practice. Use WebDriverWait instead. Commented Oct 4, 2017 at 16:47
  • Sure. You right. Commented Oct 4, 2017 at 16:49
  • Have you tried waiting for the element to be visible? selenium-python.readthedocs.io/waits.html#explicit-waits Commented Oct 4, 2017 at 16:51

1 Answer 1

1

The following code will resolve the issue.

from selenium import webdriver session = webdriver.Chrome() session.get('https://sports.williamhill.com/bet/en-gb') # REMOVE POP-UP timezone_popup_ok_button = session.find_element_by_xpath('//a[@id="yesBtn"]') timezone_popup_ok_button.click() # FILL OUT FORMS user_element = session.find_element_by_name("tmp_username") user_element.click() actual_user_elm = session.find_element_by_name("username") actual_user_elm.send_keys("myUsername") password_element = session.find_element_by_id("tmp_password") password_element.click() actual_pass_element = session.find_element_by_name("password") actual_pass_element.send_keys("myPassword") login_button = session.find_element_by_xpath('//input[@id="signInBtn"]') login_button.click() 
Sign up to request clarification or add additional context in comments.

1 Comment

Works like a charm, absolutely brilliant. Much appreciated. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.