0

I am trying to login to a site www.bet365.com

I am able to send the login information for the username, however the password box is split into both a visible and hidden element for security.

How am I able to send the password to the box in order to automate login?

I have tried accessing the visible element however when passed not all characters of the password are received.

When attempting to pass to the hidden element no password is visibly sent.

I have also tried clicking the visible element before sending but this also did not work.

wait=WebDriverWait(driver,3)
userele=wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_UserNameWrapper input.hm-Login_InputField[type="text"]')))
userele.send_keys('xyz@gmail.com')

passwdele=wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_PasswordWrapper input.hm-Login_InputField.Hidden[type="password"]')))
passwdele.send_keys('xxxxxxxxxxx')

btnelement=wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_PasswordWrapper button.hm-Login_LoginBtn')))

btnelement.click()

Here is the main code for the elements on the bet365 page

<div class="hm-HeaderModule_UserAdmin ">
<div class="hm-Login ">

<div class="hm-Login_UserNameWrapper ">
<input type="text" class="hm-Login_InputField ">
<div class="hm-Login_InputText ">Join Now</div></div>

<div class="hm-Login_PasswordWrapper ">
<input type="text" class="hm-Login_InputField ">
<input type="password" class="hm-Login_InputField Hidden ">
<button tabindex="0" class="hm-Login_LoginBtn ">GO</button>
<div class="hm-Login_InputText ">Lost Login?</div></div></div></div>

Only the username passing currently works.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Jp1875
  • 1
  • 3

2 Answers2

0

Well, you can send the password in visible input like this :

Code :

driver = webdriver.Chrome(executable_path = r'chromedriverPath')
wait = WebDriverWait(driver,10)

driver.maximize_window()

driver.get("https://www.bet365.com/#/HO/")

wait = WebDriverWait(driver, 10)

wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@title='New Customer Bonus']"))).click()

userele = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.hm-Login_UserNameWrapper input.hm-Login_InputField[type='text']")))
userele.send_keys('xyz@gmail.com')

passwdele = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.hm-Login_PasswordWrapper input.hm-Login_InputField[type='text']")))
passwdele.send_keys('xxxxxxxxxxx')

btnelement = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_PasswordWrapper button.hm-Login_LoginBtn')))

btnelement.click()  

imports would be :

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

Let me know, if you are facing any problem.

cruisepandey
  • 6,860
  • 3
  • 9
  • 24
  • Hi, thanks for your solution, however this is still cropping up the same issue of only 4 of the password keys being sent, any thoughts? – Jp1875 Apr 23 '19 at 11:45
0

You need to avoid invoking send_keys() to a hidden password box in all possible ways. However inducing WebDriverWait for the first element on the page you want to interact would be enough and you don't need to invoke WebDriverWait multiple times when interacting with <input> elements. You can try either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.hm-Login_UserNameWrapper>input.hm-Login_InputField[type='text']"))).send_keys('xyz@gmail.com')
    driver.find_element_by_css_selector("div.hm-Login_PasswordWrapper>input.hm-Login_InputField:not(.Hidden)").send_keys("hello")
    
  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='hm-Login_UserNameWrapper ']/input[@class='hm-Login_InputField ' and @type='text']"))).send_keys('xyz@gmail.com')
    driver.find_element_by_xpath("//div[@class='hm-Login_PasswordWrapper ']/input[contains(@class, 'hm-Login_InputField') and not(@class='Hidden')]").send_keys("Jp1875")
    
  • 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
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217