How to start selenium chromedriver script with already opened profile in chrome - python

I'm using selenium chromedriver with Google Chrome profiles on Mac OS and Windows. As I understand it, in the usual case the selenium script will not work if another profile in Google Chrome is open. This causes some inconvenience as a regular google chrome user - every time before I run the script I have to close the browser completely.
I would not be comfortable switching to the gecko driver because firefox does not allow me to install the extensions I need. Are there any other options on how to solve this problem?

Related

Selenium in python - Browser closing immediately after open testprogamm

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.

What modules are best to imitate selenium style of being able to login into accounts and place orders? Without opening web browser [duplicate]

I have been trying to do web automation using Selenium. Is there any way to use a browser like Chrome or Firefox without actually installing them, like using some alternate options, or having portable versions of them. If I can use portable versions how do I tell Selenium to use it?
To use the browsers like google-chrome and firefox you have to install the full-blown browser.
You can find a detailed discussion in Is Chrome installation needed or only chromedriver when using Selenium?
As an alternative you can use the headless phantomjs browser as follows:
Code Block:
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path=r'C:\WebDrivers\phantomjs.exe', service_args=['--ignore-ssl-errors=true', '--ssl-protocol=tslv1.0'])
driver.set_window_size(1920, 1080)
driver.get("https://account.booking.com/register?op_token=EgVvYXV0aCJ7ChQ2Wjcyb0hPZDM2Tm43emszcGlyaBIJYXV0aG9yaXplGhpodHRwczovL2FkbWluLmJvb2tpbmcuY29tLyo2eyJwYWdlIjoiL3JlZGlyZWN0LXRvLWpvaW5hcHAtbHA_bGFuZz1pdCZhaWQ9MTE4NzM2MCJ9QgRjb2RlKg4QAToAQgBY5dGK8gVgAQ")
print(driver.page_source)
driver.quit()
You can find a detailed discussion in PhantomJS can't load correctly web page
References
A couple of relevent discussions:
Do headless web browser need selenium WebDriver?
Difference of Headless browsers for automation
Install Selenium typing pip install selenium.
It comes with a portable version of Chrome browser, no need to manually install any browser for this.
Chrome will show this message to indicate that it is being 'remote controlled:
"Chrome is controlled by automated test software"

Run selenium with chrome driver on centos without Gui

I write some code with python selenium using chrome driver as web driver. When I run code in my system ( mac os ), the code works. Chrome browser was opened, and selenium works correctly. But when I want to run my code in Centos 7 without GUI, selenium can't match with web driver and run the code. Although I install google-chrome-stable and use the same web driver for it, selenium can't run web driver.
driver = webdriver.Chrome(driver_path=chromedrive75)
So, I don't know how to fix the code and running on my centos operating system.
#Vahid, please check the chrome web browser version which is compatible with server, also try running in headless mode.

Selenium Chromedriver disable log on Windows

I am running selenium via python 3 with the chromedriver browser on windows 10.
The program is very active and should run constantly. Means: lots of logging going on.
Problem: the crhomedriver logs get way too long after a few hours, and windows tends to crash.
Everything is working fine, the logs are just minor issues about which I do not really care.
Question:
How may I disable the chromedriver logs?
Notes:
I did my research and did not find any working solution yet.
I am forced to use chromedriver, hence no headless browser like phantomJS is a valid alternative.
Try this, not sure it will work. Pass the options to your chromedriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--disable-logging')

py2app selenium without firefox install

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

Categories

Resources