1

lastly I'm working about a Python project which uses the library "selenium". The project should type in passwords according to the usernames that it has got. My problem is that I don't know how to get data from a text box. For example, if I want to use the project on "Facebook", at first I have to get the E-mail which the user typed in (kind of like putting it as a string variable), and then I have to type in the correct password (I know how to do that). My main problem is that the command " .text " doesn't work because the E-mail isn't found in any attribute of the textbox, so I can't call it. Does someone have a solution please?

The current lines are :

driver = webdriver.Chrome('C:\\Users\User\Desktop\chromedriver.exe')
driver.get('https://www.facebook.com/stype=lo&jlou=AfdFutu6bihEQajPctMRwj2ySoaIGAE71YZ0aBZe9FYV4Xd2XuZ3SGth5wernWcF7s4pSvZH5W6f0ed2BfafHrkbupDcW4GDQECBTnhQID1FQ&smuh=4370&lh=Ac_eTqeC_DcDMq9f')
mail = driver.find_element_by_id('email').text

The problem is that the current "mail" variable is an empty string, because the E-mail textbox of Facebook's website is empty as it's waiting for the client to type in his E-mail. I'm trying to get the client's E-mail AFTER he typed it in.

Thanks in advance!

2
  • Hi, please supply what code you currently have. Commented Feb 28, 2017 at 22:01
  • driver = webdriver.Chrome('C:\\Users\User\Desktop\chromedriver.exe') driver.get('facebook.com/…) mail = driver.find_element_by_id('email').text Commented Mar 1, 2017 at 12:12

1 Answer 1

2

You can get value from input field simply as

email_input = driver.find_element_by_xpath('//input[@type="email"]')
print(email_input.get_attribute('value'))

Update

If you want to get text from input after user enter email:

driver = webdriver.Chrome('C:\\Users\User\Desktop\chromedriver.exe')
driver.get('https://www.facebook.com/stype=lo&jlou=AfdFutu6bihEQajPctMRwj2ySoaIGAE71YZ0aBZe9FYV4Xd2XuZ3SGth5wernWcF7s4pSvZH5W6f0ed2BfafHrkbupDcW4GDQECBTnhQID1FQ&smuh=4370&lh=Ac_eTqeC_DcDMq9f')
email = input("Please enter your Email: ")
email_input = driver.find_element_by_xpath('//input[@type="email"]')
email_input.send_keys(email)
print(email_input.get_attribute('value')) # or just print(email)

Note, that user should enter email value to command line, but not to browser input field

Sign up to request clarification or add additional context in comments.

6 Comments

<input type="email" class="inputtext" name="email" id="email" value="" tabindex="1"> That's how it looks. Why do you think that there is no value attribute?
Your'e right, I just didn't see the "value" there. Anyway, about your code, it works well, but the problem is that it prints the email_input before I even finish typing in my E-mail... Do you an idea to make it wait untill I finish my E-mail?
Do you want to input email value manually and then get value from field?
Yes, exactly. I want to be able to get the E-mail right after the client typed it in.
Checked that, but I need the website to work as it usually does. The user should see his E-mail typed in the textbox by the time he is typing it. Your code will show him his mail in the textbox, only after he finishes typing the whole E-mail.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.