1

I am trying to automate the take of uploading a CSV file to a web browser. If you click the button, a windows dialog box opens, you select the file, and it is uploaded as expected. I'm trying to automate this small task.

The HTML looks like this:

<input name="csvFile" id="csvFile" class="ignore-inline-attach" type="file">

The code that I'm trying to get working looks like this:

import requests
import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from webbot import Browser
driver = webdriver.Chrome(executable_path= r'C:/Users/ryans/OneDrive/Desktop/Briefcase/Python Scripts/chromedriver.exe')
web = Browser()
url = 'https://web_site'
web.go_to(url)
# 1st validation
web.type('email' , into='username')
web.click('Continue')
# 2nd validation
web.type('email' , into='username')
web.click('Next')
# password
web.type('pass' , into='password')
web.click('Next')
# Now you are logged in!!
url = 'https://web_page'
web.go_to(url)
#################################
# upload CSV Source File:
WebElement = webdriver.find_element_by_class_name('ignore-inline-attach')
WebElement.sendKeys("C:/my_path/test.csv");
#################################

When I run this code, I get the following error message:

AttributeError: module 'selenium.webdriver' has no attribute 'findElement'

I found a few sample scripts online, and tried several ideas, but I couldn't get anything working. The two lines of code that I posted above seems like the best way to move forward, but I can't seem to get this working. Does anyone here have any idea how to do this? Thanks!

dir(webdriver)
# Result:
['ActionChains',
 'Android',
 'BlackBerry',
 'Chrome',
 'ChromeOptions',
 'DesiredCapabilities',
 'Edge',
 'Firefox',
 'FirefoxOptions',
 'FirefoxProfile',
 'Ie',
 'IeOptions',
 'Opera',
 'PhantomJS',
 'Proxy',
 'Remote',
 'Safari',
 'TouchActions',
 'WebKitGTK',
 'WebKitGTKOptions',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '__version__',
 'android',
 'blackberry',
 'chrome',
 'common',
 'edge',
 'firefox',
 'ie',
 'opera',
 'phantomjs',
 'remote',
 'safari',
 'support',
 'webkitgtk']
asked Sep 7, 2018 at 14:28
10
  • 1
    What are you getting using those instructions? an error? it doesn't do anything? Please elaborate a little bit more. Commented Sep 7, 2018 at 14:31
  • Are you submitting the form after that? What error are you getting? Commented Sep 7, 2018 at 14:34
  • Whoops. I forgot to add that part. I just updated my original post. Commented Sep 7, 2018 at 14:35
  • Can you try this line of code instead: WebElement = webdriver.find_element_by_class_name('ignore-inline-attach') Commented Sep 7, 2018 at 14:45
  • I added that line and now I get this: AttributeError: module 'selenium.webdriver' has no attribute 'find_element_by_class_name' Commented Sep 7, 2018 at 15:11

1 Answer 1

2

The error is thrown because find_element_by_class_name function belongs to webdriver.driver instead of webdriver. Note that this code will open two browser windows, not one, because:

"Web automation library for python which is based on the selenium framework"

If you look at the source you can see:

self.driver = webdriver.Chrome(executable_path=driverpath , chrome_options=options)

It means that you open two tabs in these two lines:

driver = webdriver.Chrome(executable_path= r'C:/Users/ryans/OneDrive/Desktop/Briefcase/Python Scripts/chromedriver.exe')
web = Browser()

You don't actually need that. May be fixed in this way:

import requests
import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from webbot import Browser
web = Browser()
url = 'https://web_site'
web.go_to(url)
# 1st validation
web.type('email' , into='username')
web.click('Continue')
# 2nd validation
web.type('email' , into='username')
web.click('Next')
# password
web.type('pass' , into='password')
web.click('Next')
# Now you are logged in!!
url = 'https://web_page'
web.go_to(url)
# upload CSV Source File:
WebElement = web.driver.find_element_by_class_name('ignore-inline-attach')
web.driver.sendKeys("C:/my_path/test.csv");
# Close browser.
web.close_current_tag()

Glad to help you :)

answered Sep 7, 2018 at 20:02

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.