Selenium Python print out value of textfield using get_attribute('value') is not printing the value. I am getting blank printed -


i trying print out value of textfield. value not being printed out, getting blank output, empty. textfield have value on web page. using name_element.get_attribute('value') should print value of textfield. not know why not working me.

in pycharm console output is: print_value_from_name_textfield

the next line not printing out value print name_element.get_attribute('value')

i expecting value "data object name" printed value in textfield on web page. getting blank output.

my code snippet is:

def print_value_from_name_textfield(self):     name_element = self.get_element(*mainpagelocators.data_objects_name_textfield_edit)     print "print_value_from_name_textfield"     print name_element.get_attribute('value') 

the html is:

    <div class="marginbelow">         <span class="gwt-inlinelabel defaultformlabelwidthcompact myinlineblock">name</span>         <input id="data_configuration_edit_data_object_tb_name" class="gwt-textbox" type="text"/>     </div> 

in mainpagelocators textfield id defined as:

from selenium.webdriver.common.by import class mainpagelocators(object):     data_objects_name_textfield_edit = (by.id, 'data_configuration_edit_data_object_tb_name') 

get_element implementation is:

# returns element if found def get_element(self, how, what):     # params how: locator type     # params what: locator value     try:         element = self.driver.find_element(by=how, value=what)     except nosuchelementexception, e:         print         print "element not found "         print e         screenshot_name = how + + get_datetime_now() # create screenshot name of name of element + locator + todays date time.  way screenshot name unique , able save         self.save_screenshot(screenshot_name)         raise     return element 

what doing wrong please? thanks, riaz

if unfortunately get_attribute('value') not work, can try using execute_script() input value below :-

print self.driver.execute_script("return arguments[0].value",name_element) 

edited: if value in input field loaded after time, should implement implicit wait before finding input element below :

self.driver.implicitly_wait(10)  name_element = self.get_element(*mainpagelocators.data_objects_name_textfield_edit) print "print_value_from_name_textfield" print name_element.get_attribute('value') 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -