1

I am trying to get the value of a textfield. The textfield is in an Input tag in the html. I want to print out it's value. I am getting nothing printed out to the console. I have identified the element with the following XPATH

By.XPATH, '//span[@class="gwt-InlineLabel marginbelow myinlineblock" and contains(text(), "Type")]/following-sibling::*'

My code snippet is

 def get_type_field_value(self):
        type_field_element = self.driver.find_element(By.XPATH, 'By.XPATH, '//span[@class="gwt-InlineLabel marginbelow myinlineblock" and contains(text(), "Type")]/following-sibling::*'')
        print type_field_element.text

The HTML is:

<div class="clear">
    <span class="gwt-InlineLabel marginbelow myinlineblock" style="width: 8em;">Type</span>
    <input class="gwt-TextBox marginbelow" type="text" disabled="" style="display: inline;"/>
 </div>

I have also tried the following method:

def get_type_field_value2(self):
    return self.driver.execute_script("""
        return jQuery(arguments[0]).contents().filter(function() {
        return this.nodeType == Node.TEXT_NODE;
        }).text();
        """, self.driver.find_element(By.XPATH, '//span[@class="gwt-InlineLabel marginbelow myinlineblock" and contains(text(), "Type")]/following-sibling::*'))

I get a JavaScript error:

raise exception_class(message, screen, stacktrace)
WebDriverException: Message: JavaScript error

How do i get the value of the Textfield?

Thanks,

2
  • There is no text in the html of the <input> tag. Commented Sep 17, 2015 at 13:05
  • So i cannot use.Text then. How do i get the value then. Ah i could use .value. Value is for input tags. I will try that. Commented Sep 17, 2015 at 13:09

1 Answer 1

3

Since value is simply an html attribute, you can get the attribute value using -

print type_field_element.get_attribute('value')
Sign up to request clarification or add additional context in comments.

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.