1

I'm trying to locate elements 1. password 2. submit button

CSS Paths from firebug :

for password:

...textfield-1023.x-field.loginpage-email-textfield.x-form-item.x-form-item-default.x-form-type-text.x-box-item.x-field-default.x-vbox-form-item...

for button

...
button-1028.x-btn.loginpage-login-button.x-unselectable.x-box-item.x-toolbar-item.x-btn-default-small span#button-1028-btnWrap.x-btn-wrap.x-btn-wrap-default-small 
...

code:

e_passwd = driver.find_element_by_css_selector(".loginpage-password-textfield")
action_passwd = ActionChains(driver)
action_passwd.move_to_element(e_passwd)
action_passwd.click(e_passwd)
action_passwd.send_keys("symbol")
action_passwd.perform()

e_submit = driver.find_element_by_css_selector(".loginpage-login-button")
action_button = ActionChains(driver)
action_button.move_to_element(e_submit)
action_button.click(e_submit)
action_button.perform()

This code is able to locate and click the submit button but not able to locate password field.

Is there any other method I need to use to locate the textfield elements ?

Saifur
  • 16,081
  • 6
  • 49
  • 73
Rameswar
  • 13
  • 3

1 Answers1

1

Firebug is a great tool. But does not give you what you need all the time. So, sometime it is helpful to know how to write selector manually. See this thread Simply use. Css allows you to add multiple attributes with [] to identify the element uniquely.

[placeholder='Password'][type='password']

Just another option if you want to use xpath with find_element_by_xpath you can also use the following:

//input[@placeholder='Password'][@type='password']

or

//input[@placeholder='Password' and @type='password']

as @alecxe suggested

Api doc is here

Community
  • 1
  • 1
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • @alecxe Thanks for the edit and upvote. BTW now I copy paste your name don't even try spelling :P – Saifur Feb 24 '15 at 16:54
  • Yeah, this is definitely easier. Btw, should not the xpath be `//input[@placeholder='Password' and @type='password']`? – alecxe Feb 24 '15 at 16:56
  • Thanks Saifur! Your solution is working perfectly. I'm able to locate using following line also `e_passwd = driver.find_element_by_css_selector("[type='password']")` But i want to use **.loginpage-password-textfield** also while locating as it is not going to change further. – Rameswar Feb 24 '15 at 17:01
  • @Rameswar I don't see `loginpage-password-textfield` class in the `html` you provide. How you are getting it? – Saifur Feb 24 '15 at 17:05
  • if i copy the css path using firebug i'm able to see it. Not able to get the same using HTML. – Rameswar Feb 24 '15 at 17:08
  • @Rameswar not sure then `Firebug` is misleading you then. The `CSS` I provided is pretty static and I use something very similar for my testing as well – Saifur Feb 24 '15 at 17:10
  • it is in outer division. `
    ` which is displayed with css.
    – Rameswar Feb 24 '15 at 17:10
  • I guess you want to use `placeholder` then. I ran into the same situation testing my site. Not really sure if you can use the class even the id from that outer division. Probably not. – Saifur Feb 24 '15 at 17:12