Find Value Using Selenium using a Variable that Contains String


I am trying to open up several URL’s (because they contain data I want to append to a list). I have a logic saying "if amount in icl_dollar_amount_l" then run the rest of the code. However, I want the script to only run the rest of the code on that specific amount in the variable "amount".


selenium opens up X amount of links and sees ['144,827.95', '5,199,024.87', '130,710.67'] in icl_dollar_amount_l but i want it to skip '144,827.95', '5,199,024.87' and only get the information for '130,710.67' which is in the 'amount' variable already.

Actual results:

Its getting webscaping information for amount '144,827.95' only and not even going to '5,199,024.87', '130,710.67'. I only want it getting webscaping information for '130,710.67' because my amount variable has this as the only amount.


['144,827.95', '5,199,024.87', '130,710.67']



def scrapeBOAWebsite(url,fcg_subject_l, gp_subject_l):

    from ICL_Awk_Checker import  rps_amount_l2

    icl_dollar_amount_l = []
    amount_ack_missing_l = []
    file_total_l = []
    body_l = []

    for link in url:
        browser = webdriver.Chrome(options=options,
        # if 'P2 Cust ID 908554 File' in fcg_subject:
        username = browser.find_element_by_name("dialog:username").get_attribute('value')
        submit = browser.find_element_by_xpath("//*[@id='dialog:continueButton']").click()
        body = browser.find_element_by_xpath("//*[contains(text(), 'Total:')]").text
        icl_dollar_amount = re.findall('(?:[£$€]{1}[,d]+.?d*)', body)[0].split('$', 1)[1]
     if not missing_amount:"List is empty")
        print("List is empty")
     count = 0
     for amount in missing_amount:
        if amount in icl_dollar_amount_l:
            body = body_l[count]
            get_file_total = re.findall('(?:[£$€]{1}[,d]+.?d*)', body)[0].split('$', 1)[1]

    return icl_dollar_amount_l, file_date_l, company_id_l, client_id_l, customer_name_l, file_name_l, file_total_l, 
           item_count_l, file_status_l, amount_ack_missing_l


I don’t know if I understand problem but this

 if amount in icl_dollar_amount_l:

doesn’t give information on which position is '130,710.67' in icl_dollar_amount_l and you need also

 count = icl_dollar_amount_l.index(amount)

for amount in missing_amount:
    if amount in icl_dollar_amount_l:
        count = icl_dollar_amount_l.index(amount)
        body = body_l[count]

But it will works if you expect only one amount on list icl_dollar_amount_l. For more elements you would have to use rather for-loop and check every element separatelly

for amount in missing_amount:
    for count, item in enumerate(icl_dollar_amount_l)
        if amount == item :
             body = body_l[count]

But frankly I don’t know why you don’t check it in first loop for link in url: when you have direct access to icl_dollar_amount and body

Source: stackoverflow