3

In a html page I have the following snippet:

<div class="jupyter-widgets widget-hbox widget-text">
    <div class="widget-label" style="display: block;">Walltime:</div>
    <input type="text" class="form-control" placeholder="">
</div>

in which the input element renders, like expected, as an input field. However, this input field has some value in it.

Using the inspector of the browser it is possible to select that element and use the following expression in the console to get that value:

$0.value

However, how to do this in python-selenium?

When I have the input element in a variable named 'input' I have tried the following:

driver.execute_script("arguments[0].value;", element)

which does not return the value in that input box, but None instead. How to do it correctly to retrieve the value from that 'input' box?

1
  • 1
    have you tried element.text? Commented Feb 27, 2019 at 13:04

2 Answers 2

4

You need to return the value

driver.execute_script('return arguments[0].value;', element)

You can also use get_attribute()

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

Comments

3

With get_attribute you can get any attribute of an element! in your case:

element.get_attribute("value")

As @Guy commented text is not part of the html so don't use:

element.text

2 Comments

element.text won't work, the text is not part of the html.
@Guy I was just asking you why not to use text :)

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.