0

I'm trying to fill out a Username and Password field on a website. The id changes every time, so I cant find the elements by using the id. So I tried by using XPath and class name, but none of them worked. This is my code:

user_name_elem = driver.find_element_by_xpath("//input[contains(@class, 'mu-input__field mu-input__field--error')]")
user_name_elem.click()
user_name_elem.clear()
user_name_elem.send_keys('example@gmail.com')

for the password, I tried the same and it didn't work, for both I just I get an "unable to locate element".

This is the HTML of the Website:

The field for E-mail Adress:

<input type="email" id="lfte2w" name="emailAddress" placeholder="E-Mail-Adresse" autocomplete="on" class="mu-input__field mu-input__field--error"> 

For the password:

<input type="password" id="c2juvc" name="password" placeholder=" Passwort" autocomplete="on" class="mu-input__field">

And this is the link to the Login page: https://www.mueller.de/login/

1
  • you have link to the website? – PDHide Jun 8 at 16:36
0

Use correct XPath to find the locator, once the locator is correct you can very well use the .sendkeys() method to type into the field. use chrome browser inspect element and try not to overcomplicate the XPath. For the username and password fields usually, a simple locator will work like id, name, type anything. You are using the @contains function which is not required.

1
  • Thank you! I will try it! Would really like to upvote, but I don't have enough reputation yet. – LordB Jun 9 at 12:23
0

What about using the 'name' of the element?

Something like this (in Python) - find_element(By.NAME, "emailAddress") - similar thing for "password".

2
  • Thanks! It worked but now I got i new Problem, see above in the comment section of Mats answer. – LordB Jun 9 at 12:13
  • I got it working, Thanks anyway!! – LordB Jun 9 at 12:29
0

Use name tag for locating elements.

// For Email Address
username = driver.find_element_by_name('emailAddress')
// For Password
password = driver.find_element_by_name('password')

For better understanding, you can check Locating Elements

2
  • Thanks! It finds the element now. I imported the common.keys import Keys, but if I try to use sendkeys() it doesn't fill out the field. And pycharm doesn't suggest it to me either if I start typing. Btw: I would really like to upvote your comments but I can't do that yet with only 1 reputation. – LordB Jun 9 at 12:11
  • Solved it. Thanks anyways!! – LordB Jun 9 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.