user11960891
user11960891

Reputation:

Selenium Is not typing right thing with for loop python

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

Upvotes: 0

Views: 64

Answers (1)

Abhiram Satputé
Abhiram Satputé

Reputation: 604

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.

Upvotes: 1

Related Questions