0

Hi guys I want to get the text from element which is disabled.It's value depends upon the domain of email address I fill during sign up.The HTML code for the element is:

<select _ngcontent-thq-32="" class="form-control formInputHeight ng-untouched ng-pristine" data-dropdownjs="true" id="compName" name="companyId" required="" disabled="">
    <option _ngcontent-thq-32="" disabled="disabled" selected="selected" value="0">Company Name</option>
    <!--template bindings={}-->
</select>

And the Python code I'm using to get the text from this element is:

disabled_input_field = driver.find_element_by_xpath('//*[@id="compName"]')
    value = disabled_input_field.get_attribute('value')
    return value

But everytime my test case fails.Please suggest the correct method of doing so.

2 Answers 2

1

The problem is that you are trying to retrieve the value of the SELECT element, which it itself has no value. You want to get the value from the selected OPTION.

from selenium.webdriver.support.ui import Select
...
return Select(driver.find_element_by_id("compName")).first_selected_option.text
Sign up to request clarification or add additional context in comments.

Comments

0

Me seems you are not looking for the right element, but for its parent. Try something like this instead:

disabled_input_field = driver.find_element_by_xpath('//*[@id="compName"]/option')
value = disabled_input_field.get_attribute('value')
return value

2 Comments

Not working still...Can you tell if this piece of code will return the text in that field/element to me or the element?
Well, could you please provide more information then. What error do you get. In what line is the error? The above snippet will not return any text, it will return the attribute "value", which appears to be set to 0. What exactly would you want to retrieve?

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.