简体   繁体   中英

How to verify attribute text for a validation error message using python selenium?

I am trying to verify that validation errors exist on a page after submitting the page when the fields are not filled in/selected.

I have found that the html shows that the "style" attribute is different when the error displays, so I want to verify that "style" text.

Here is the html from the page:

ERROR NOT DISPLAYED

    <div class="errorDiv2">
    <span id="MainContent_ClinicName_mbRequiredValidator" class="errorMsg" style="display:none;">Please provide clinic name.</span>

ERROR DISPLAYED

    <div class="errorDiv2">
    <span id="MainContent_ClinicName_mbRequiredValidator" class="errorMsg" style="display: inline;">Please provide clinic name.</span>

I have been able to find the id using xpath and driver.find_element_by_id, but not the text in the style attribute (display: inline;).

I have used this code, but it finds the id regardless and doesn't find the text in the attribute.

clinicNameError = driver.find_elements_by_xpath("//*[@id='MainContent_ClinicName_mbRequiredValidator']['@style=display: inline;']")

Have you tried something like this:

clinicNameError = driver.find_elements_by_xpath("//*[contains(@id,'MainContent_ClinicName_mbRequiredValidator') and contains(@style, 'inline')]");

or by class?

clinicNameError = driver.find_elements_by_xpath("//*[contains(@id,'MainContent_ClinicName_mbRequiredValidator') and contains(@class, 'errorMsg')]");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM