Tuesday, February 5, 2019

py0004 : Begginner error, Open Firefox

I have written the code and getting two type error from 3 rows of code that is ridiculous:
First error belongs to the Firefox driver which was not found and gives error like  "File "C:/Users/*****/Desktop/python/example/0001.py", line 3, in "

Second type of error is "NameError: name 'selenium' is not defined" as name showcase something not found related to selenium

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = selenium.webdriver.Firefox()

Error on execution of code 
C:\Users\*****\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/*****/Desktop/python/example/0001.py
Traceback (most recent call last):
  File "C:/Users/*****/Desktop/python/example/0001.py", line 3, in
    driver = selenium.webdriver.Firefox()
NameError: name 'selenium' is not defined

Process finished with exit code 1


SOLUTION:
Add path for Firefox driver that you have downloaded from internet and add "Import selenium" at first line

import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = selenium.webdriver.Firefox(executable_path= r'C:\\Users\\*****\\Desktop\\python\\geckodriver-v0.24.0-win64\\geckodriver.exe')

Run the Code, Firefox will open automatically

No comments:

Post a Comment

web stats