1

I am a big fan of Karate and exploring Karate UI for the end to end testing but stuck on one simple thing which is finding element by attribute where element contains special charatcers like below

<input autocapitalize="none" autocomplete="on" autocorrect="off" name="session[username_or_email]" spellcheck="false" type="text" dir="auto" data-focusable="true" class="r-30o5oe r-1niwhzg r-17gur6a r-1yadl64 r-deolkf r-homxoj r-poiln3 r-7cikom r-1ny4l3l r-1inuy60 r-utggzx r-vmopo1 r-1w50u8q r-1lrr6ok r-1dz5y72 r-1ttztb7 r-13qz1uu" value="">

This is the html snippet taken from Twitter login page. To get this control I have tried various options from mentioned below but couldn't able to find the control

Option 1

  Given driver 'https://twitter.com/login'
  And input('#session[username_or_email]',['aaaa@gmail.com',Key.ENTER], 100)
  And input('#session[password]',['asasas', Key.ENTER], 100)
  When submit().click("click('{span}Log in')")
  #* def elements = locateAll('{div}Click Me')
  Then locate('.css-901oao').exists

Option 2

  Given driver 'https://twitter.com/login'
  And input('input[name=session[username_or_email]]', 'aaaa@gmail.com')
  When submit().click("click('{span}Log in')")
  Then locate('.css-901oao').exists

I above tried options I couldn't able to find input and span button. Any help or pointer will be very helpful.

Atul Chaudhary
  • 3,698
  • 1
  • 31
  • 51

1 Answers1

1

Here you go, note how you can use double-quotes when needed. I'm also giving an alternate approach, input[type=text] would have also worked:

* input("input[name='session[username_or_email]']", 'hello')
* input('input[type=password]', 'world')
* click('div[role=button]')
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    My next question would be how do i find nested span via parent class or text within span. I will try with locateAll but what is the best approach. Thanks for the answer – Atul Chaudhary Apr 13 '20 at 14:02
  • @AtulChaudhary ask a new question with an example (thanks for that !) and I can answer, we only just added a way to chain `locate()` on an element in git - but maybe this answer will give you some workarounds: https://stackoverflow.com/a/60618233/143475 – Peter Thomas Apr 13 '20 at 14:05