0

I am using python's selenium and trying extract the text into a list or dataframe. Iam trying get the text"M" from class="flex">M. Put this and another item into a dataframe and then loop and do again adding rows to a dataframe.

elm_result1 = driver.find_element_by_css_selector("span[flex ng-bind='LB.record.SEX_CD']")
print("Total results: ", elm_result1.text)

HTML

<span flex-gt-sm="" layout="row" class="layout-row flex-gt-sm">
    <span class="summaryLabel shorterLabel">Gender</span>
    <span flex="" ng-bind="LB.record.SEX_CD" class="flex">M</span>
</span>

and another similar structure

<span flex="" ng-bind="(LB.record.FIRST_NAME)" class="flex">A</span>

Error message

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
  (Session info: chrome=75.0.3770.142)

1 Answer 1

1

Use the below css.

elm_result1 = driver.find_element_by_css_selector("span.flex[ng-bind='LB.record.SEX_CD']")
print("Total results: ", elm_result1.text)

Screenshot:

enter image description here

Sign up to request clarification or add additional context in comments.

14 Comments

Use this css span.flex[ng-bind^='(latestBene.record.BRTH_DT ']
how can I fix this code and write to a csv file? its currently looping through but not append after each input is recorded. The list comes out [] blank.
Can you please post a new question, just don't want the things get complicated and messed up by answering a different question here.
Can you take a look at this question thank you. stackoverflow.com/questions/59433697/…
|

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.