0

I Want To Fill The data in input

i have 250 records in my sheet

i want to fill country with currency and code and click on submit and then second country currency and code then third

But The Problem is When i try to run my this code:

It's Not Changing Country And Currency for example if i had two countries Afghanistan and Albania

my script want to write Afghanistan first time and hit submit and the next time it want to write Albania

but it's only typing Afghanistan again and again!

Here is the Video So You Guys Can Understand Better!

enter image description here

Here is my code:

from selenium import webdriver
import pandas as pd


count = pd.read_csv('c.csv')
list_of_c = count['COUNTRY'].to_list()
cur = pd.read_csv('cur.csv')
list_of_cur = cur['CUR'].to_list()

co = pd.read_csv('code.csv')
list_of_code = co['CODE'].to_list()


def code():
    driver = webdriver.Chrome()
    driver.get('http://lachisolutions.com/bitcoinerrs/countries.php')
    for code in list_of_code:
        for countrys in list_of_c:
            for curs in list_of_cur:
                country = driver.find_element_by_css_selector('.text-center+ .form-group .form-control').send_keys(str(countrys))
                currency = driver.find_element_by_css_selector('.form-group:nth-child(3) .form-control').send_keys(str(curs))
                code = driver.find_element_by_css_selector('.form-group~ .form-group+ .form-group .form-control').send_keys(str(code))
                button = driver.find_element_by_css_selector('.btn-block').click()

code()

c.csv

COUNTRY
Afghanistan
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antigua and Barbuda
Argentina

It's Only Writing Currency in right way

3
  • Please be more clear in the expected result. Your code seems to imply you want to go over ALL currencies for each country. I highly doubt that's what you want? Commented Nov 29, 2019 at 8:33
  • The output is correct since the for loop of the country is outside the for loop of currency, so it will iterate over all the currencies for one country, then change the country and iterate over all the currencies, and so on. Just revise the concept of nested for loop once. Commented Nov 29, 2019 at 9:06
  • @AbhiramSatputé Now It's Typing All Countries in one time in one input i don't need like that i want 1 country and submit then 2nd country Commented Nov 29, 2019 at 9:12

1 Answer 1

1

Try this:

from selenium import webdriver
import pandas as pd


count = pd.read_csv('c.csv')
list_of_c = count['COUNTRY'].to_list()
cur = pd.read_csv('cur.csv')
list_of_cur = cur['CUR'].to_list()

co = pd.read_csv('code.csv')
list_of_code = co['CODE'].to_list()


def code():
    driver = webdriver.Chrome()
    driver.get('http://lachisolutions.com/bitcoinerrs/countries.php')
    for code in list_of_code:
        i = 0
        while True:
            try:
                country = driver.find_element_by_css_selector('.text-center+ .form-group .form-control').send_keys(str(list_of_c[i]))
                currency = driver.find_element_by_css_selector('.form-group:nth-child(3) .form-control').send_keys(str(list_of_cur[i]))
                code = driver.find_element_by_css_selector('.form-group~ .form-group+ .form-group .form-control').send_keys(str(code))
                button = driver.find_element_by_css_selector('.btn-block').click()
                i+=1
            except Exception as e:
                break

code()

You should also provide the expected output format along with the values in the other csv files.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.