1

I am a beginner so please excuse me if my coding is a little excessive. I am trying to import an .xlsx file and use the fields in the spreadsheet in place of the 'email', 'password', 'first name','last name', and 'city' that are on the script. I also want the script to loop until all of the fields are properly input into the script.

Here is a picture of the spreadsheet I'd like to use:

enter image description here

Here is the script:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common import action_chains, keys
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import ElementNotVisibleException
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
from random import randint
from multiprocessing import Process
from threading import Thread
import threading
import time, sys, os


root_url='https://www.nike.com/us/en_us/p/settings'

url='https://www.nike.com/us/en_us/p/settings'


driver = webdriver.Chrome('/Users/mileswalker/chromedriver')

driver.set_window_position(0, 0)

driver.set_window_size(500, 500)



driver.maximize_window()
driver.implicitly_wait(0.5)
driver.get(url)
time.sleep(0.5)
wait = WebDriverWait(driver, 10)



#Email
driver.find_element_by_name('emailAddress').send_keys("johndoe@example.com")

print "Successfully Entered Email..."   


#Password

driver.find_element_by_xpath("//input[@placeholder='Password']").send_keys("Example") 

print "Successfully Entered Password..."    

#Login Button

driver.find_element_by_xpath("//input[@value='LOG IN']").click()

time.sleep(10.0)


#First Name
driver.find_element_by_xpath('//*[@id="first-name"]').clear()
driver.find_element_by_xpath('//*[@id="first-name"]').send_keys("John")

print "Successfully Entered First Name..."

#Last Name
driver.find_element_by_xpath('//*[@id="last-name"]').clear()
driver.find_element_by_xpath('//*[@id="last-name"]').send_keys("Doe")

print "Successfully Entered Last Name..."


#City
driver.find_element_by_xpath('//*[@id="town"]').clear()
driver.find_element_by_xpath('//*[@id="town"]').send_keys("District Heights")

print "Successfully Entered City..."

time.sleep(2.5)

#Save Button
driver.find_element_by_xpath('//*[@id="content"]/div[1]/div[2]/div[1]/form/div[18]/button[2]').click()

print "Successfully Saved Account Information..."

time.sleep(2.5)

#Logout

driver.find_element_by_xpath('/html/body/div[8]/nav/div[1]/ul[2]/li[1]').click()
driver.find_element_by_xpath('//*[@id="exp-profile-dropdown"]/ul/li[9]').click()

print "Successfully Logged Out..."
print "Moving On To The Next Nike Account."

driver.close()
BioGenX
  • 402
  • 3
  • 11
Miles Walker
  • 35
  • 1
  • 8
  • Have a read here: http://stackoverflow.com/questions/22169325/read-excel-file-in-python . Should be easy to change the code to fit your need – BioGenX Mar 25 '17 at 04:28
  • 1
    There are several packages out there that handle xlsx files, a web search and some tutorials would be a good start. Alternately, you could save the table to a CSV file and use python's standard `csv` module or even the `pandas` module. Lot of options! – tdelaney Mar 25 '17 at 04:29
  • I agree with @tdelaney, CSV will be a good option in your case. – Wenlong Liu Mar 25 '17 at 04:41
  • Ok thanks I will try CSV. – Miles Walker Mar 25 '17 at 04:44

1 Answers1

0

I prefer pyopenxl library. It is easy to read/write excel files with it.

https://openpyxl.readthedocs.io/en/default/

Artagel
  • 390
  • 1
  • 12