-1

I am new to selenium and want to use it to test login page. I have below text field in which I want to insert username.

<div class="WODM WNDM" data-automation-id="userName">
<div class="gwt-Label WBEM">Email Address</div><input type="text" 
class="gwt-TextBox WAEM" autocapitalize="none" autocorrect="off" 
autocomplete="off" aria-label="Email Address" dir="ltr">
</div>

I have written below code which is not working:

emailElem = driver.find_element_by_class_name('gwt-Label WBEM')
emailElem.send_keys('some_email')

Thanks in advance!

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • @Andersson How does the question about `want to insert username` be a duplicate to `Compound class names not permitted`? By all possible means it's not a duplicate. Can you consider to reopen it? – undetected Selenium Aug 18 '18 at 06:57
  • 3
    @DebanjanB , Do you see any questions here? I see only code that leads to `Compound class name not permitted Exception` and issue description *"... code which is not working"*. This is obvious duplicate. See no reason to reopen – Andersson Aug 18 '18 at 07:15
  • @Andersson Rather answering my question you are defending your wrong descission. Question have a clear objective, code attempts and relevant html. Pretty much legit question. But how come `want to insert username` be a duplicate to `Compound class names not permitted`. Of-coarse OP is a new user and _code attempt_ is wrong and that's where OP needs help. Does that answers your question? This is pretty much **unwelcoming** !!! – undetected Selenium Aug 18 '18 at 07:19
  • @Andersson I think you are messing up two things _helping OP to insert username_ and _a discussion about **Compound class names not permitted**_. First of all, perhaps the dup could have better been a pointer in solving OP's question but never a _duplicate_. Second, while commenting please chose your words with utmost care as these comments including words like **littering** are exposed to _global audience_. Third, do you still see any any answer from me? At-times all you need is to encourage the other volunteers attempting to answer. Hope this helps you to take a informed decision. – undetected Selenium Aug 18 '18 at 07:45
  • 1
    @DebanjanB , Did you see the code? OP **knows how to insert value in text field**. This is not the issue. The issue is **wrong code for selecting element**. And OK... Check [this question](https://stackoverflow.com/questions/51896615/how-to-pull-out-text-from-a-div-class-using-selenium-headless/51896844). This is obvious duplicate of [this](https://stackoverflow.com/questions/20996392/how-to-get-text-with-selenium-web-driver-in-python). Why you didn't close the ticket? Why answering to question that was already answered hundred times? – Andersson Aug 18 '18 at 07:56
  • @Andersson If OP had known _how to insert value in text field_ with 100% accuracy this question would have been never raised in the first place. The other question which you are referring is not a duplicate of the [question](https://stackoverflow.com/questions/20996392/how-to-get-text-with-selenium-web-driver-in-python) which is pretty generic. There is a lot of fundamental difference between the two questions. – undetected Selenium Aug 18 '18 at 08:04
  • @Andersson So do you still feel this question as a duplicate? – undetected Selenium Aug 18 '18 at 09:27
  • @DebanjanB, I've updated the title to reflect the actual current issue. Now it's 100% duplicate – Andersson Aug 18 '18 at 09:50
  • 2
    @Andersson This question is being discussed [on meta](https://meta.stackoverflow.com/q/372738/4916627). Maybe you want to give your view of the situation. – André Kool Aug 18 '18 at 11:08
  • @DebanjanB thanks! I want a solution to this particular code snippet. I tried other answers but couldn't figure out how to use it for this problem. Thanks again everyone! – Siddhant Tanpure Aug 23 '18 at 19:31
  • @SiddhantTanpure Please update the question with your latest code trials ensuring that `Compound class names not permitted` is not raised and mark @Andersson in your reply so he gets notified and reopens the question to allow the volunteers to answer your question. – undetected Selenium Aug 23 '18 at 19:37

2 Answers2

0

3 things I can see:

  1. Should call clear() before sending keys.
  2. You have entered two classes as you would see them in HTML - I'm pretty sure selenium only expects one in the call so chose wisely (please confirm this point - if its not too much trouble, would be goo to know for sure.
  3. I'm seeing that the classes your trying to select gwt-Label and WBEM are this is a <label></label> - shouldn't you be calling the <input></input> which has the two classes: gwt-TextBox and WAEM

So with those three points in mind you should change your code to:

emailElem = driver.find_element_by_class_name('gwt-TextBox')
emailElem.clear()
emailElem.send_keys('some_email')
SagarScript
  • 1,145
  • 11
  • 15
  • No this is not working. I don't think I can use that class name to select the text input field as that is a compound class name not sure though. – Siddhant Tanpure Aug 18 '18 at 04:04
  • Just edited the thread - picked up another point! You're selecting the wrong class I think! Try this: emailElem = driver.find_element_by_class_name('gwt-TextBox') – SagarScript Aug 18 '18 at 04:09
0

You can use xpath as below

driver.find_element_by_xpath("//input[@type='text' and @class='gwt-TextBox WAEM']")
Sodium
  • 1,016
  • 1
  • 9
  • 22