When i run the code, browser is opening but not at all loading anything.
i want to login into website using selenium.
im using windows 7 64 bit os and python 2.7.
i have downloaded drivers from https://github.com/mozilla/geckodriver/releases
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
path="D:\New folder (2)\geckodriver-v0.20.0-win64/geckodriver.exe"
driver = webdriver.Firefox(executable_path=path)
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()
screen shot
when i close the browser it shows this error
error
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 0
You main issue is in the GeckoDriver absolute path which you have assigned to path.
You need to pass the argument executable_path along with the absolute path of the GeckoDriver binary through either of the following options :
Double back slashes (\\)
Single back slash (\) along with the raw (r) switch.
So you have to change the line :
path="D:\New folder (2)\geckodriver-v0.20.0-win64/geckodriver.exe"
To either :
path="D:\\New folder (2)\\geckodriver-v0.20.0-win64\\geckodriver.exe"
Or :
path=r'D:\New folder (2)\geckodriver-v0.20.0-win64\geckodriver.exe'
Related
I set up a celery environment and released two tasks. One is to open Google Chrome, and the other is a simple addition calculation. There is no problem with the function of addition calculation, but the function of opening the browser reports an error, and the browser cannot be opened.
The error:
File
"d:\software\professional\python27\lib\site-packages\selenium\webdriver\common\service.py",
line 95, in start
(os.path.basename(self.path), self.start_error_message, str(e))) WebDriverException: Message: The executable chromedriver needs to be
available in the path. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
set_nonblocking() on a file object with no setblocking() method
(Windows pipes don't support non-blocking I/O)
enter image description here
my code:(tasks.py)
# -*- coding:utf-8 -*-
from selenium import webdriver
import time
from proj.celery import app
import os
#app.task
def chrome_test():
chrome_options = webdriver.ChromeOptions()
driver_path1 = r"chromedriver"
driver_path2 = os.path.join(r"D:\SoftWare\Professional\ChromeDriver", "chromedriver.exe")
# print "try to open chrome..."
driver = webdriver.Chrome(executable_path=driver_path1, options=chrome_options)
# executable_path=driver_path, options=chrome_options
print "open chrome success"
driver.get("https://www.baidu.com/")
time.sleep(1)
print driver
driver.close()
return "success to open chrome..."
#app.task
def add(x, y):
time.sleep(1)
return x+y
if __name__ == "__main__":
chrome_test()
But if I run the function alone, it can work very well.
This error message...
File "d:\software\professional\python27\lib\site-packages\selenium\webdriver\common\service.py", line 95, in start (os.path.basename(self.path), self.start_error_message, str(e)))
WebDriverException: Message: The executable chromedriver needs to be available in the path. Please see https://sites.google.com/a/chromium.org/chromedriver/home set_nonblocking() on a file object with no setblocking() method (Windows pipes don't support non-blocking I/O)
...implies that your program was unable to locate the ChromeDriver while trying to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
In your code block you have used:
driver = webdriver.Chrome(executable_path=driver_path1, options=chrome_options)
Where,
driver_path1 = r"chromedriver"
Hence, your program can't locate the chromedriver.exe.
Solution
You need to mention the absolute path of the ChromeDriver as follows:
driver = webdriver.Chrome(executable_path=r'D:\SoftWare\Professional\ChromeDriver\chromedriver.exe', options=chrome_options)
Alternatively, using os.path.join() you can use:
driver_path2 = os.path.join(r"D:\SoftWare\Professional\ChromeDriver", "chromedriver.exe")
driver = webdriver.Chrome(executable_path=driver_path2, options=chrome_options)
References
You can find a couple of relevant discussions in:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome
WebDriverException: Message: 'chromedriver' executable needs to be in PATH while setting UserAgent through Selenium Chromedriver Phyton
Error Message: 'chromedriver' executable needs to be PATH
tl; dr
Non-blocking read on a subprocess.PIPE in python
I was add the parameter "-P eventlet" when starting the "celery" service. I encountered this problem, and then I removed the parameter and the problem was solved.
celery -A proj worker -l info -P eventlet (old)
celery -A proj worker -l info
I suspect there is a threading issue between windows and "-P eventlet" and celery. The specific reason is not clear.
How do we get ctypes.CDLL("jvm.dll") to not find the dll and not give a "module not found" error?
We have verified the paths and can get them through file "open" commands of the jvm.dll - but the exact same paths when given to ctypes gives a "module not found" error.
We also tried editing the registry keys as per this answer.
We have also tried both running a 32 bit version of Python with a 32 bit version of Java as well as trying 64 bit versions.
We are working in Python 2.7.14 on Windows Server 2016.
Why could this be failing and what else can we try? Is there something preventing the Python script from seeing DLLs?
Here is more background:
The reason we are trying to get ctypes to work is because jpype is failing with the same error- and thus they seem foundationally related to the Python modules not being able to see or access the DLL.
When we run the following commands...
>> import ctypes
>> import os
>> os.chdir(r"C:\Program Files (x86)\Java\jre1.8.0_181\bin\client\")
>> ctypes.CDLL("jvm.dll")
...we get "module not found."
Yet, we can reach the file with open commands. For example, this call works from within Python (note it also works for the x86 path used above) to reach the jvm.dll:
>>> fo = open("C:\\Program Files\\Java\\jre1.8.0_181\\bin\\server\\jvm.dll")
But this call via Jpype fails even though is pathed to the same file:
>>> import jpype
>>> jpype.startJVM("C:\\Program Files\\Java\\jre1.8.0_181\\bin\\server\\jvm.dll")
Jpype gives the following error:
File "C:\Python27\lib\site-packages\jpype_core.py", line 70, in
startJVM
_jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to load DLL [C:\Program Files\Java\jre1.8.0_181\bin\server\jvm.dll],
error = The specified module could not be found. at
native\common\include\jp_platform_win32.h:58
The reason we are using jpype is we are trying to get Jaydebeapi working to create a JDBC connection to a database.
How do we enable ctypes (and presumably thus jpype) to find and use the jvm.dll?
Our answer to solving this was to move from using the Python 2.7 interpreter to using Jython.
Using Jython, we were able to use the Jadebeapi library and connect to the database over JDBC.
I've been asked to evaluate Robotframework and happy with what I've seen for the most part. For it to be a viable option for me however, I need it to work in Firefox.
Marionette capabilities were a problem in my Ruby/Capybara environment, and I was able to shut it off.
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox, desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false))
end
Getting the same thing in Robot / Python 2.7 / ff44.0 has generated an error in either direction.
When marionette is on:
${dc} Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.FIREFOX sys, selenium.webdriver
Set To Dictionary ${dc} marionette=${True}
Open Browser ${url_bck_auto} Firefox desired_capabilities=${dc}
I get this:
Our products rock | FAIL |
WebDriverException: Message: Unsupported Marionette protocol version
2, required 3
If I turn it off, gecko bumps me to ff51.0.1(32-bit) and I get a different message:
Our products rock | FAIL |
WebDriverException: Message: Can't load the profile. Possible firefox
version mismatch. You must use GeckoDriver instead for Firefox 48+.
Profile Dir: c:\users\blah\appdata\local\temp\tmpqzlxha\webdriver-
py-profilecopy If you specified a log_file in the FirefoxBinary
constructor, check it for details.
Geckodriver is version 0.15.0
Any help will be appreciated, thanks!
On Windows 10 I'm running Robot Framework 3.0, Selenium2Library 1.8.0, Selenium 3.0.2 and when I start your example, or the simplified single open browser http://google.com I get the same result when using Gecko 0.15.0. The browser starts but does not move to the desired page. The driver closes successfully but the browser stays open.
When using the same setup, but downgrading Geckodriver to 0.14.0 the results change, and the browser behaves as expected. Loads the page and closes when Close Browser keyword is called.
So, I recommend downgrading to Geckodriver 0.14.0.
I am running OS X 10.9.4 on my laptop, with Chrome 40.0.2214.94 and Selenium 2.44.0, which I installed for Python 2.7 with easy_install. My code is this basic code from a selenium walkthrough:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
But when I run this I get an exception:
Traceback (most recent call last):
File "/Users/masongardner/Desktop/Selenium_tester.py", line 17, in <module>
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
File "/Library/Python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 59, in __init__
self.service.start()
File "/Library/Python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 66, in start
"ChromeDriver executable needs to be available in the path. "
selenium.common.exceptions.WebDriverException: Message: ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
As the documentation specifies, chrome is at this location on my machine:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
What can I do to get around this problem and begin to retrieve data from certain pages as I had planned? If you could be very explicit about code changes or location changes, as I am not the most well versed in computing!
Thanks everyone, and I hope my question isn't too simple!
ChromeDriver is a binary file that interfaces WebDriver with Chrome. If you have WebDriver's libraries installed, and Chrome installed, you still need the ChromeDriver binary in a location that WebDriver can find it.
As the error message indicates, you need to get the binary from here:
http://chromedriver.storage.googleapis.com/index.html
And then place the binary file somewhere on your PATH. Optionally, you can tell WebDriver where the binary is by setting a system property. I would start off by placing the binary somewhere on your PATH and get more specific/complex if you need to.
/usr/bin is on the global path for OS X, so that's a good place to put the file. Plus, it would be available to any user on the computer. You can open up that folder by opening a Finder window, choosing the Go -> Go To Folder in the menu, then entering in /usr/bin (you'll probably be asked for your password as it's a system location.) Then just copy the ChromeDriver binary file into there.
Use '/usr/local/bin/chromedriver'. This worked for me:
import selenium
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chromedriver = '/usr/local/bin/chromedriver'
browser = webdriver.Chrome(chromedriver)
browser.get('https://stackoverflow.com/users/login')
To work around this issue on Mac OXS El Capitan 10.11.6, I have added a copy of chromedriver executable file to:
/Library/Python/2.7/site-packages/selenium/webdriver
I'm having trouble running some codes that import cx_Oracle in command line, though the same codes work in console. Is there anything else I will need to set up in order to get this to work via command line please?
Saved just one line of code "import cx_Oracle" as test.py.
Run this line in ide (Spyder), iPython Notebook => no issues
run this by opening a command line window from the same folder the .py file is saved in, and run python test.py and encounter the below:
import cx_Oracle
ImportError: DLL load failed: %1 is not a valid Win32 application.
Not sure if there is anything additional I will need to set up to run cx_Oracle via command line? Have tried all the suggestions on setting PATH, ORACLE_HOME, re-installing but could not get this to work. versions that i'm using are
Python: 2.7
cx_Oracle: cx_Oracle-5.1.3-11g.win-amd64-py2.7
instant client: 12.1.0.0
Windows: 7 Enterprise
I also found this kind of problem.
Look at "not a valid Win32 application" this sentence, so I decide to change cx_Oracle to cx_Oracle-5.1.3-11g.win-32-py2.7. Luckly, it does work.