error while opening tor browser using Python selenium firefoxdriver - selenium-webdriver

i am trying to open tor browser using selenium python
this is the code
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
#path to TOR binary
binary = FirefoxBinary(r'C:\Users\OKILAN\Desktop\Tor
Browser\Browser\firefox.exe')
#path to TOR profile
profile = FirefoxProfile(r'C:\Users\OKILAN\Desktop\Tor
Browser\Browser\TorBrowser\Data\Browser\profile.default')
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
driver =webdriver.Firefox(capabilities=cap,firefox_binary=binary,executable_path=r'C:\Users\OKILAN\Desktop\geckodriver.exe')
driver.get("http://stackoverflow.com")
time.sleep(5)
driver.quit()
When i run the code it shows tor failed to start
and i got the below error
Traceback (most recent call last):
File "C:\Users\OKILAN\Desktop\test1.py", line 13, in <module>
driver = webdriver.Firefox(capabilities=cap,firefox_binary=binary,executable_path=r'C:\Users\OKILAN\Desktop\geckodriver.exe')
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 191, in __init__
self.binary, timeout)
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 73, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 104, in _wait_until_connectable
"The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
help me to solve this error:-(

You do not need all the binary and profile stuff, to create driver only use this line
driver = webdriver.Firefox(executable_path="C:\\geckodriver.exe")
driver.get("http://stackoverflow.com")
make sure you have downloaded and set geckodriver to environment
1
First download GeckoDriver for Windows, extract it and copy the path
to the folder.
Right-click on My Computer or This PC. Select Properties.
Select
advanced system settings. Click on the Environment Variables button.
From System Variables select PATH. Click on Edit button. Click New
button. Paste the path of GeckoDriver file.

Related

driver.get("https://www.python.org") not working

I am trying to learn Selenium with python.
So trying to access a website but it is not working
from selenium import webdriver
driver = webdriver.Chrome(executable_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
driver.implicitly_wait(5)
driver.maximize_window()
driver.get("https://www.python.org/")
Error in Console:
/usr/local/bin/python3.7 /Users/adeshpande/PycharmProjects/Selenium/Tests/LoginPagesTest.py
Traceback (most recent call last):
File "/Users/adeshpande/PycharmProjects/Selenium/Tests/LoginPagesTest.py", line 6, in <module>
driver = webdriver.Chrome(executable_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /Applications/Google Chrome.app/Contents/MacOS/Google Chrome unexpectedly exited. Status code was: 0
Your are passing the path to the Chrome Browser in your call webdriver.Chrome.
You should be passing the path to ChromeDriver which is a separate program. You can download it from https://chromedriver.chromium.org
After downloading and installing it, pass the path to where you installed it and you should be good to go!

Running Selenium with Python3 on Remote Server - Error NotADirectory, Gecko Not on PATH

I am having this problem getting selenium to run with python3. The first is when I do:
from selenium import webdriver
driver = webdriver.Firefox()
I get the error geckodriver is not PATH. I downloaded geckodriver from https://github.com/mozilla/geckodriver/releases then create a directory called gecko and do
export PATH=$PATH:/home/ubuntu/gecko
I repeat the process of declaring the webdriver and then I got this error:
File "", line 1, in
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 135, in init
self.service.start()
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.4/subprocess.py", line 859, in init
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
NotADirectoryError: [Errno 20] Not a directory
I already have xvfb installed for running the browser headless and issue the command xvfb-run python3 to start the python interactive shell. I am baffled as to why I continue to get this error message.
How do I solve it? Your help is much appreciated.
Thanks.

Error in libcloud and vsphere integration

I am using libcloud 1.2.1 with pysphere 0.1.7. I am getting the below error when trying to connect to the ESXi host.
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/libcloud/compute/drivers/vsphere.py", line 152, in init
port=port, url=url)
File "/Library/Python/2.7/site-packages/libcloud/common/base.py", line 1177, in init
self.connection = self.connectionCls(args, *conn_kwargs)
TypeError: init() got an unexpected keyword argument 'retry_delay'
I am using the below commands to connect to the host.
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
vsphere = get_driver(Provider.VSPHERE)
driver = vsphere(host='',username='username',password='password')
I can do this using pysphere only but not with libcloud. Tried looking on the internet and changing the content of the libraries but in vain. Can anyone help ?
This is a bug in v1.5.0<, there is a committed fix. You can apply the patch manually using git am: https://patch-diff.githubusercontent.com/raw/apache/libcloud/pull/967.patch
Wait for v1.6.0, or install directly from GitHub trunk
pip install git+https://github.com/apache/libcloud.git#trunk#egg=apache-libcloud

How to run selenium python script using chrome browser in ubuntu

I'm getting error like that and i have seen below URL and i don't know how to configure with ubuntu(12.04). I know how to configure chrome web driver with windows. Please see below error if any body knows send me a answer.
Traceback (most recent call last):
in setUp driver = webdriver.Chrome() File "/home/pyd/pydan/venvs/local/lib/python2.7/site- packages/selenium/webdriver/chrome/webdriver.py",
line 60, in __init__ self.service.start() File "/home/pyd/pydan/venvs/local/lib/python2.7/site- packages/selenium/webdriver/chrome/service.py",
line 64, in start and read up at
http://code.google.com/p/selenium/wiki/ChromeDriver")
WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.
If you checkout this link, http://code.google.com/p/selenium/wiki/ChromeDriver,
there is useful info on where to find the chrome binary on Linux. Also, you might want to check your path environmental variable.

Does GAE accept twill at all?

I have created my GAE application in directory "my_application". Inside this directory I created a .py file and named it "my_scrypt".
The contents of "my_scrypt" in the beginning were as following:
print 'Content-Type: text/plain'
print ''
print 'This is my first application'
Then I ran it locally on my machine (Windows XP) in the installed browser (Mozilla FireFox) with "GAE Launcher" - everything was fine - I could see that sentence ("This is my first application") on the screen.
Then I deployed this application to GAE (again with the help of "GAE Launcher") - everything was fine again - I could see the same sentence on the screen.
Then I changed the contents of "my_scrypt" a bit:
from twill.commands import *
config('use_tidy', '0')
go ("http://us.yahoo.com/")
showlinks()
Downloaded "twill0.9" (from here), chose and copied "twill" folder from there, and pasted it in "my_application" directory.
When I ran this new application locally (with "GAE Launcher") everything was fine - I could see a list of yahoo.com links on the screen, but when I uploaded this application to GAE, I received only an error message.
Why is it so? I don't think it's because the version of mechanize being used by twill here is too old - the code in "my_script" is so simple, any version of mechanize must be able to handle it.
Does GAE accept twill (as an external module) at all?
You can view the stack trace of the error in the "Update 1" section right below (↓).
UPDATE 1:
(This update is my answer to Nick)
Hello, Nick. I checked the admin console, so here is the stack trace:
<type 'exceptions.ImportError'>: No module named fcntl
Traceback (most recent call last):
File "/base/data/home/apps/silkybutton/1.344911014283513184/bumper.py", line 1, in <module>
from twill.commands import *
File "/base/data/home/apps/silkybutton/1.344911014283513184/twill/__init__.py", line 52, in <module>
from shell import TwillCommandLoop
File "/base/data/home/apps/silkybutton/1.344911014283513184/twill/shell.py", line 9, in <module>
from twill import commands, parse, __version__
File "/base/data/home/apps/silkybutton/1.344911014283513184/twill/commands.py", line 70, in <module>
from browser import TwillBrowser
File "/base/data/home/apps/silkybutton/1.344911014283513184/twill/browser.py", line 17, in <module>
from _browser import PatchedMechanizeBrowser
File "/base/data/home/apps/silkybutton/1.344911014283513184/twill/_browser.py", line 9, in <module>
from utils import FixedHTTPBasicAuthHandler, FunctioningHTTPRefreshProcessor
File "/base/data/home/apps/silkybutton/1.344911014283513184/twill/utils.py", line 12, in <module>
import subprocess
File "/base/data/home/apps/silkybutton/1.344911014283513184/twill/other_packages/subprocess.py", line 378, in <module>
import fcntl
Twill is trying to import 'subprocess'. This is a Python module for spawning threads, and it's not available on App Engine. You'll either need to see if you can persuade Twill to work without spawning processes (probably by modifying the code), or you'll need to use mechanize or simply urlfetch directly.

Resources