I am trying to automation some action on a website using Python and Selenium, this is the sample code I am trying to run, from the Mozilla website for running the Firefox webdriver
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
caps["binary"] = "/usr/bin/firefox-aurora"
driver = webdriver.Firefox(capabilities=caps)
driver.get("https://www.google.com")
driver.quit()
When running this code, the Firefox instance opens normally, and I can even use the instance as if I just opened Firefox normally, but the code 'stops' executing at the driver = webdriver.Firefox(capabilities=caps) line, I tried debugging the code with no luck, the whole execution seems to just stop at this line, and nothing after it is reached!
I am running Python3.5, Selenium version 2.53.6, I have the 'Wires' executable at the /usr/local/bin which is in the environment's PATH, I also have Firefox Aurora version 49.0a2 running on ArchLinux.
Thanks in advance.
[Update:]
I managed to get it to work after all using Firefox 46 (the normal version).
Related
As soon as I run my program, google opens (so far so good) but this window closes immediately after the program has run. I already installed the chromdriver (also matches the version of the search engine) and put it in the script folder in Python. Can someone help me?
Here is my Code:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://google.com")
You need to specify an excecutable path for a chrome driver to be able to open a browser.
download a driver based on your browser in your case it's Chrome from here: https://chromedriver.chromium.org/downloads
then driver = webdriver.Chrome(here you have to write the path of the driver),you can put it wherever you want.
I am currently trying to launch google chrome with a certain chrome extension using Selenium and Python. The script works partially, google chrome detects and launches with the extension I wish to add though after the browser launches it closes almost instantly (error code: "...selenium.common.exceptions.SessionNotCreatedException: Message: session not created"). How do I keep the browser open after chrome launches with the extension? The script does not read anything past the driver launch, "driver = webdriver.Chrome(options=options, executable_path=r'C:/Webdriver/chromedriver.exe')"
code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
unpacked_extension_path = '/path/to/unpacked/extension/''
options = Options()
options.add_argument('--load-extension={}'.format(unpacked_extension_path))
driver = webdriver.Chrome(options=options, executable_path=r'C:/Webdriver/chromedriver.exe')
driver.get('example.com')
I have tried adding "chrome_options.add_experimental_option("detach", True)" and/or "global driver."Any help would be very appreciated!
screen-capture:
https://gyazo.com/52d6d6e6cfa61f5d8660204d773b5d03
I installed selenium and chrome driver.
I then created the below code to run it:
from pyvirtualdisplay import Display
from selenium import webdriver
chromedriver = "/usr/bin/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get(url)
html = driver.page_source
driver.quit()
display.stop()
The code yields the following error: "'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home"
The path is correct. I have tried some variations of the code but they all yield the same message. My webhost claims you cant install selenium on a centos server that has cpanel. Is this true or is there something wrong with my code?
you might use OS.environ and chromeoptions
I am running following code in PyCharm
from selenium import webdriver
driver = webdriver.Firefox
Scripts executes successfully with following message in console
C:\Python34\python.exe C:/Users/dev/PycharmProjects/PYLearn/firs_selenium_script.py
Process finished with exit code 0
But Firefox Browser is not opening, I have selenium installed using pip, Do I need additional setting to make this work.
Thanks,
To launch the browser your code should look like:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://your-url')
After the test you will want the close the browser, so add:
self.browser.quit()
Hope this solve your problem.
More info: http://selenium-python.readthedocs.org/getting-started.html
Go to Python Console at the bottom and run your commands and check the error
You can try this:
from selenium import webdriver
browser = webdriver.Chrome()
Browser should be opened , anyways check whether the browser started running or not.
Once, your browser fully loaded, your command will move to next line
I am wondering if there is a way within py2app to include the Firefox browser, or if there is a way for Selenium to use Firefox without having to install Firefox on the host machine.
I have created an app with py2app that uses Selenium, however, I have Firefox installed on my machine, but not everyone that will receive the app will have Firefox installed. I am looking for a way to either include Firefox in the distribution or go around this.
Script will not run if Firefox is not preinstalled.
You can test your script with other browser, for example Chrome. If it works on Chrome also, then you can edit script like this:
from selenium.common.exceptions import WebDriverException
try:
driver = webdriver.Firefox()
except WebDriverException:
driver = webdriver.Chrome()
You can add same for few more browsers (IE, Opera, Safari...) to be sure that script will run on users machine