0

I'm trying to log in to a website using selenium and python. This is what the html for the username and password look like. The name and id are random strings everytime, so how would I use selenium to type in the form? The xpath and css selector I found using inspect element on chrome both contain the id, which doesn't really work since the id is random.

<input name="u41f98d000f26d904164eaf12622351bd" id="u41f98d000f26d904164eaf12622351bd" type="text" value="" autocomplete="off" tabindex="1">

<input name="pa0ef2cd4e22824cebe65dfed7f683c54" id="pa0ef2cd4e22824cebe65dfed7f683c54" type="password" value="" autocomplete="off" tabindex="2">

Sorry if this is a dumb question, I'm new to python and selenium

2 Answers 2

2

There are two possibilities that stand out for unique selectors.

  1. type - type="text" and type="password"
  2. tabindex - tabindex="1" and tabindex="2"

I think in this case, tabindex is probably better.

user_inp = "username"
pass_inp = "password"

username = driver.find_element_by_css_selector("input[tabindex='1']")  
password = driver.find_element_by_css_selector("input[tabindex='2']")

username.send_keys(user_inp)
password.send_keys(pass_inp)
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to form XPath, you can either use one or both of them as mentioned by Richard:

username = driver.find_element_by_xpath("//input[@tabindex='1' and @type='text']")
password = driver.find_element_by_xpath("//input[@tabindex='2' and @type='password']")

Comments

Your Answer

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