1

I want to output this data to a csv file. Currently, it's not appending anything when getting to the css_selector the text is not being appended. I want to append it to a list, then in a dataframe and then to a csv file.

list1=[]
for i, j in df1.iterrows():
    name = j[1]
    id1 = j[2]
    sleep(3)
    BI_box = WebDriverWait(driver, 
    10).until(EC.presence_of_element_located((By.ID,'BI')))
    BI_box.send_keys(id1)

    Last_Name_box = WebDriverWait(driver, 
    10).until(EC.presence_of_element_located((By.ID,'last')))
    Last_Name_box.send_keys(name)

    Sea= WebDriverWait(driver, 
    10).until(EC.presence_of_element_located((By.ID,'srch')))
    Sea.click()
    try:
        elm_result = driver.find_element_by_css_selector("span.flex[ng- 
        bind='(lbecord.F)']").text
        list1.append(elm_result)
        print(elm_result)
        print(list1)
    except:
        pass
    try:
        elm_result4 = driver.find_element_by_css_selector("span.flex[ng- 
        bind^='(la.record.B_DT ']").text
        list1.append(elm_result4)
    except:
        pass

    try:
        elm_result12 = driver.find_element_by_css_selector("span[ng- 
        bind='row.RISK_IND']").text
        list1.append(elm_result12)
    except:
        pass
    sleep(2)
    clear_btn = driver.find_element_by_id('clr')
    clear_btn.click()
    sleep(2)
    print(list1)

How do I solve the problem?

7
  • 1
    Have to tried with explicit wait after clicking on the search? Does your code execute atleast one try block successfully? Commented Aug 6, 2019 at 2:53
  • 1
    @supputuri No I used a print statement under the first try and it printed. then under the elm_results and nothing prints Commented Aug 6, 2019 at 3:12
  • 1
    I tried WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID,("span.flex[ng-bind=' .... same result. Commented Aug 6, 2019 at 3:14
  • 1
    Try adding EC.presence_of_element_located in each try block. I am sure either the script is not waiting for some element to be present or the locators might need to revisited. Commented Aug 6, 2019 at 3:17
  • 1
    elm_result = driver.find_element_by_css_selector("span.flex[ng- bind='(lbecord.F)']").text there is a typo in the css try with span.flex[ng-bind^='(LB.record.F'] Commented Aug 6, 2019 at 3:25

0

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.