I have updated to Selenium 3. I have set gecko in PATH but continue to get the error. Firefox starts up but then no action for a few moments and Firefox closes (i assume a time out).Any incite would be greatly appreciated!
Traceback (most recent call last):
File "C:\Users\Paul\Documents\python selenium\python_org_search.py", line 4, in
driver = webdriver.Firefox()
File "C:\Python27\lib\selenium\webdriver\firefox\webdriver.py", line 78, in init
self.binary, timeout)
File "C:\Python27\lib\selenium\webdriver\firefox\extension_connection.py", line 49, in init
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "C:\Python27\lib\selenium\webdriver\firefox\firefox_binary.py", line 106, in _wait_until_connectable
% (self.profile.path))
WebDriverException: Message: Can't load the profile. Profile Dir: c:\users\paul\appdata\local\temp\tmphptyx9 If you specified a log_file in the FirefoxBinary constructor, check it for details.
EDIT:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
Related
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 4")
driver = webdriver.Chrome
('C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe', options=options)
Successfully opens my profile, it won't search for this website nor click any xpaths.
My chrome driver is located at C:\\webdrivers\\chromedriver.exe but when I use that instead of C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe it won't open my profile, just a non signed-in version of chrome :(
If I use
C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe
instead it returns this error:
Traceback (most recent call last):
File "C:\Users\oacoo\OneDrive\Desktop\bots\bot\xoldver\likesmodule\password reset\passcode.py", line 18, in <module>
driver = webdriver.Chrome('C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe', options=options)
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service C:\Users\oacoo\AppData\Local\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
help me load a page using my chrome profile please!
when i run my script , i got this error
Traceback (most recent call last):
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 992, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/ishaq/AppData/Local/Programs/Python/Python36/headless.py", line 9, in <module>
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
here is my script
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location =
r'C:\Users\ishaq\Desktop\chrome\chromedriver.exe'
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"),
chrome_options=chrome_options)
driver.get("http://www.duo.com")
magnifying_glass = driver.find_element_by_id("js-open-icon")
if magnifying_glass.is_displayed():
magnifying_glass.click()
else:
menu_button = driver.find_element_by_css_selector(".menu-trigger.local")
menu_button.click()
search_field = driver.find_element_by_id("site-search")
search_field.clear()
search_field.send_keys("Olabode")
search_field.send_keys(Keys.RETURN)
assert "Looking Back at Android Security in 2016" in driver.page_source
driver.close()
If we analyze the logs it seems the main issue is with in start os.path.basename(self.path) and subsequent error message:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
So it's clear from the error that the Python client was unable to locate the chromedriver executable binary.
You need to take care of a couple of things as follows:
chrome_options.binary_location : The parameter points to the chrome.exe not the chromedriver.exe
os.path.abspath("chromedriver") will pick up the file path of chromedriver but won't append chromedriver.exe at the end.
Here is the sample code on my windows-8 system to start google-chrome-headless:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("http://www.duo.com")
print("Chrome Browser Initialized in Headless Mode")
driver.quit()
print("Driver Exited")
I am very new to python and trying to build a solution using Python + Selenium.
I have created a module to initialize my webdriver:
DriverEngine.py:
import os
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from MyFirstSeleniumPyProject.FrameworkEngine.Constants import BrowserConstants
class DriverInitialize:
def InitializeChromeDriver(self):
browser_name = BrowserConstants.Chrome
print(browser_name)
driver = DriverConfiguration.ConfigureChromeDriver(None)
return driver
class DriverConfiguration:
def ConfigureChromeDriver(self):
driver = webdriver.Chrome(ChromeDriverManager().install())
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("window-size=1920,1080")
# preferences
chrome_options.add_experimental_option('prefs', {
'download.default_directory': get_download_path(),
'profile': {
'password_manager_enabled': False,
'disable-popup-blocking': 'true'
}
})
driver = webdriver.Chrome(chrome_options=chrome_options)
return driver
def get_download_path():
dir_path = os.getcwd()
return dir_path
I'm trying to invoke above driver function in my test file:
Chrome_Test.py
from MyFirstSeleniumPyProject.FrameworkEngine.Drivers import DriverEngine
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
class AssertGooglePage:
def navigate_url(self,url):
self.driver = DriverEngine.DriverInitialize.InitializeChromeDriver(None)
self.driver.get(url)
AssertGooglePage.navigate_url(None, url="https://www.google.com")
ErrorLog:
C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\Scripts\python.exe C:/Users/user/PycharmProjects/TestAutomation.Selenium.Practice/MyFirstSeleniumPyProject/Tests/Chrome_Test.py
Chrome
[WDM] - Current google-chrome version is 84.0.4147
[WDM] - Get LATEST driver version for 84.0.4147
[WDM] - Driver [C:\Users\user\.wdm\drivers\chromedriver\win32\84.0.4147.30\chromedriver.exe] found in cache
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\sande\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\sande\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/TestAutomation.Selenium.Practice/MyFirstSeleniumPyProject/Tests/Chrome_Test.py", line 10, in <module>
my = AssertGooglePage.navigate_url(None, url="https://www.google.com")
File "C:/Users/user/PycharmProjects/TestAutomation.Selenium.Practice/MyFirstSeleniumPyProject/Tests/Chrome_Test.py", line 7, in navigate_url
self.driver = DriverEngine.DriverInitialize.InitializeChromeDriver(None)
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\MyFirstSeleniumPyProject\FrameworkEngine\Drivers\DriverEngine.py", line 11, in InitializeChromeDriver
driver = DriverConfiguration.ConfigureChromeDriver(None)
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\MyFirstSeleniumPyProject\FrameworkEngine\Drivers\DriverEngine.py", line 47, in ConfigureChromeDriver
driver = webdriver.Chrome(chrome_options=chrome_options)
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
When I use similar snippet in same file, it works perfectly:
from selenium import webdriver
#import chromedriver_binary
from webdriver_manager.chrome import ChromeDriverManager
import time
# Select webdriver
driver = webdriver.Chrome(ChromeDriverManager().install())
# Select page load time out
driver.set_page_load_timeout(10)
# Navigate to url
driver.get("https://www.google.com")
# Sleep
time.sleep(3)
# Assertion
isTitle = driver.title=="Google"
if(isTitle):
print("Google page opened successfully!")
else:
print("Google page did not opened successfully!")
driver.quit()
Can some one suggest what's wrong with my scripts?
Please Note: I am not keeping Chromedriver at any location instead downloading at run time.
Seems like your script does not know where you Chrome Driver (Selenium) is located.
Try to use the following code to point Selenium to where you downloaded the Chrome Driver:
driver = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")
When i'm running this code:
from selenium import webdriver
import time
driver = webdriver.Chrome('C:/Program Files
(x86)/Google/Chrome/Application/chrome.exe')
driver.get('https://www.google.com/')
It only opens my browser but not the URL that was passed as a parameter to driver.get().
Given below is the traceback:
Traceback (most recent call last):
File "C:\Users\efiqq\OneDrive\Plocha\Python\Link.py", line 4, in <module>
driver = webdriver.Chrome('C:/Program Files (x86)/Google/Chrome/Application/chrome.exe')
File "C:\Users\efiqq\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\efiqq\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\efiqq\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:/Program Files (x86)/Google/Chrome/Application/chrome.exe unexpectedly exited. Status code was: 0
The path you have to pass is not to chrome.exe. You have to point to the chromedriver.exe;
You can get it here: http://chromedriver.chromium.org/downloads
Hi I just downloaded and installed selenium but, I can't figure out how to get it working I am using the following example as a test....
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox() #this is where I hit the error
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
assert "Google" in driver.title
driver.close()
I do not have firefox installed on my computer is this why it is giving me an error?
this is the error output I get when I try and run it
Traceback (most recent call last):
File "C:/Python27/test/helloworld.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 60, in __init__
self.binary, timeout),
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 60, in launch_browser
self._start_from_profile_path(self.profile.path)
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 83, in _start_from_profile_path
env=self._firefox_env).communicate()
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
startupinfo)
WindowsError: [Error 87] The parameter is incorrect
Following line starts Firefox browser so yes, it requires installed Firefox.
driver = webdriver.Firefox()
If you don't have Firefox installed you can use different browser instead:
webdriver.Opera
webdriver.Ie
webdriver.Chrome
...
See
help(webdriver)