0

The objective is to sent both username and password key into a Website login page. No link can be provided for privacy reason.

For this, I had tried both the Xpath and CSS selector approach. However, each technique give me a different error.

For example, using the xpath approach as below;

user_id =self.browser.find_elements_by_xpath("//[@id='tcl_MainContentPlaceHolder_tcl_Username']")
user_id.send_keys( 'username' )

user_pw = self.browser.find_elements_by_xpath("//*=[@id='tcl_MainContentPlaceHolder_tcl_Password']")
user_pw.send_keys( '12345678' )

will output an error;

AttributeError: 'list' object has no attribute 'send_keys'

Whereas, using CSS selector as below;

user_id= WebDriverWait( self.browser, 20 ).until(EC.presence_of_element_located( (By.CSS_SELECTOR, 'tcl_MainContentPlaceHolder_tcl_Username.form-control.input-lg') ) )

user_id.send_keys( 'username' )

will output an error

selenium.common.exceptions.TimeoutException: Message: 

I had play around with different xpath & css path, but, it does not provide any better result.

The full html/path to each of the username box and password are given below;

User Name

<div class="form-group m-b-tcl">
 <input name="tcl$MainContentPlaceHolder$tcl$Username" type="text" 
 id="tcl_MainContentPlaceHolder_tcl_Username" class="form-control input-lg" 
 placeholder="Username" autocomplete="off">
 <span id="tcl_MainContentPlaceHolder_tcl_UserNameRequired" 
  style="color:#CC0011;visibility:hidden;"></span>
</div> 

Password

<div class="form-group m-b-tcl">
 <span id="tcl_MainContentPlaceHolder_ctl00_PasswordRequired" 
 style="visibility:hidden;"></span>  <input name="tcl$MainContentPlaceHolder$ctl00$Password" 
 type="password" id="tcl_MainContentPlaceHolder_tcl_Password" 
 class="form-control input-lg" placeholder="Password">
</div>

I really appreciate if someone can show where did I do wrong. Thanks in advance.

2 Answers 2

1

find_elements_by_xpath() will returns as list.You need to change it find_element_by_xpath() which returns as webelement.

user_id =self.browser.find_element_by_xpath("//[@id='tcl_MainContentPlaceHolder_tcl_Username']")
user_id.send_keys( 'username' )

For second one your css selector is wrong.For id you need to add # when you are using css selector.

user_id= WebDriverWait( self.browser, 20 ).until(EC.presence_of_element_located( (By.CSS_SELECTOR, '#tcl_MainContentPlaceHolder_tcl_Username.form-control.input-lg') ) )
user_id.send_keys( 'username' )
Sign up to request clarification or add additional context in comments.

1 Comment

argh, thanks for point out the diff btw element & elements and #. Appreciate it
1
AttributeError: 'list' object has no attribute 'send_keys'

You do get this Error because find_elements_by_xpath is returning a list. You should try find_element_by_xpath

user_id =self.browser.find_elements_by_xpath("//[@id='tcl_MainContentPlaceHolder_tcl_Username']")

Besides that, the Xpath is not a legal expression, because you do not specify the Tag you are searching for. Try Following:

user_id =self.browser.find_element_by_xpath("//input[@id='tcl_MainContentPlaceHolder_tcl_Username']")
user_id.send_keys( 'username' )

user_pw = self.browser.find_element_by_xpath("//input[@id='tcl_MainContentPlaceHolder_tcl_Password']")
user_pw.send_keys( '12345678' )

Comments

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.