0

The html part that I am interested in like that

<div class="col-xs-12 col-md-4">
                                <select ng-show="ReadOnly != true" ng-model="SaveModel.Address_GOV_Code" class="ng-pristine ng-valid ng-not-empty ng-touched">
                                    <option value="0" ng-selected="gov.Id == 0"></option>
                                    <!-- ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:1">القاهرة</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:2">الإسكندرية</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:3">بورسعيد</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:4">السويس</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:11">دمياط</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:12">الدقهلية</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:13">الشرقية</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:14">القليوبية</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:15">كفر الشيخ</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:16">الغربية</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:17">المنوفية</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:18">البحيرة</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:19">الاسماعيلية</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:21">الجيزة</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:22">بنى سويف</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:23">الفيوم</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:24">المنيا</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:25">اسيوط</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:26">سوهاج</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:27">قنا</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:28">أسوان</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:31">البحر الاحمر</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:32">الوادي الجديد</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:33" selected="selected">مطروح</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:34">شمال سيناء</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:35">جنوب سيناء</option><!-- end ngRepeat: gov in Govs --><option ng-repeat="gov in Govs" ng-value="gov.Id" ng-selected="gov.Id == SaveModel.Address_GOV_Code" class="ng-binding ng-scope" value="number:36">الاقصر</option><!-- end ngRepeat: gov in Govs -->
                                </select>
                                <div class="form-control ng-hide" ng-show="ReadOnly == true">Matruh</div>
                            </div>

And I have used these lines in python selenium

for inputElement in driver.find_elements_by_xpath('//div[@class="form-control ng-hide"]'):
    print(inputElement.text)

But I got blank strings as a return. I expected for the html part for example to get Matruh

I couldn't post the html source of the iframe I am working on directly here Here's a link of a text file of the html source https://anonfiles.com/l8M0n533ud/HTML_txt

1 Answer 1

1

If it is just one element then why find_elements ?

use this :

print(driver.find_element_by_css_selector("div.form-control.ng-hide").text)

Update 1 :

wait = WebDriverWait(driver, 10)
print(wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.form-control.ng-hide"))).text)

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

14 Comments

Thanks a lot. There are similar elements that I need. Generally, I got blank string too when trying css_selector.
did you try with above one ? if that does not work, there should be appropriate exception
Yes, I tried your solution and doesn't work for me.
I would like to know what error it threw ?
can you try this xpath : - //input[contains(@class, 'ng-pristine ng-untouched ng-valid')]/following-sibling::div
|

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.