Is possible to use Selenium with Python, for Electron apps? - python

I am pretty new to the Selenium testing with Electron apps; I know how to use Python to drive Chrome via the webdriver, and how to use Selenium IDE on Firefox, but I am having trouble to find a good source of info.
So far I have an app made with Electron, and I would like to use Selenium to drive it and automate the basics. I did some research and most of the results were using node.js, which I do not know at all. I would like to use Python, so before moving on a whole different language, I would like to ask to a bigger audience, if there is something already to do Selenium testing with Python, on Electron apps
In particular, how do you assign the variable that will contain the electron app? with the browser I would say
from selenium import webdriver
driver = webdriver.Chrome('/chromedriver')
but this won't make sense for an electron app.

I did find a way to catch the application.
You need to download Chromedriver; and run it on a port that you like(example: 8765).
Then you can access the application written via Electron, in Python using
from selenium import webdriver
remote_app = webdriver.remote.webdriver.WebDriver(
command_executor='http://localhost:8765',
desired_capabilities = {'chromeOptions':{ 'binary': '/myapp'}},
browser_profile=None,
proxy=None,
keep_alive=False)
Then you can access the DOM elements on the app as usual. Not sure if it will work on Windows, OSX and Linux, will have to try.

Yes you can do it with driver options and capabilities.
You need to set binary path and you should add Arguments on options.
Binary path is your electron application path under project directory in '.bin'.
Argument path is your project's main directory.
For example :
Let's say, your project under home directory and named 'ElectronProject'
Binart path is '/Users/Home/ElectronProject/node_modules/.bin/electron'
Argument Path is '/Users/Home/ElectronProject'

Yes, It is possible. you can refer the documentation # https://electronjs.org/docs/tutorial/using-selenium-and-webdriver

Related

How to use headless chrome in python on vercel?

You may know that heroku will stop their free dyno, free postgres etc from November. So I was finding some alternative to run my python web apps. I have almost 10 regular web apps which I visit regularly, like: url shortener, keyword research, google drive direct link generator site and many more. All of these are hosted on heroku. But I'm moving to vercel now. I setup all projects on vercel but the last one is complicated. My last project is python selenium bot. This one is my keyword research web app. I used some buildpack eg: Headless Chrome (https://github.com/heroku/heroku-buildpack-google-chrome) and Chromedriver (https://github.com/heroku/heroku-buildpack-chromedriver) to make this project run properly. But the problem is I could not find anything like buildpack in vercel to add Chrome and Chromedriver.
Anyone know about this?
Edit:
That was a kind of story and many people didn’t understand what I was asking.
So, My project is about selenium (python). Selenium needs google chrome browser installed and a chromedriver to run itself. There is another option without installing chrome is to set chrome binary location in webdriver.ChromeOptions(). I want to host this selenium project on vercel.com which is linux based.
So my question is how can I install Chrome Browser and ChromeDriver in vercel?

Python Selenium: Is there a way to install webdriver inside the virtual enviroment

I'm planning to build my first web automation project using selenium.
But before that, I'd like to know is there a way to install the web driver inside the virtual environment. I looked in the documentation that you should place the web driver inside the python bin folder, but I would like it to be inside a virtual environment. If there is a way to do that, please show the steps to do it.
If you bundle a WebDriver into the virtual environment, you should also include the browser itself... since it is bound with the browser.
Therefore, it is not recommended to bundle WebDriver with your app that way, and instead you should just run WebDriver separately from your client.
If you really look for bundling WebDriver with your app, you should rather user Docker, since it will allow you to properly install a browser, for example, there is a ready image on Docker hub for that, including Python, Chrome, Chromedriver and some of them also Xvfb.

How to "add" geckodriver to PATH on ScrapingHub?

I am using python2 for web scraping, I have written a spider that uses headless Firefox (no GUI) to go on a website, log in with my account and furthermore interact with the website by pressing buttons, filling forms, calendars, etc. It works as expected on my personal computer, however, once I deploy it to Scrapinghub I get the error saying that geckodriver needs to be on path.. That directory already is on PATH on my computer, just not on Scrapinghub.
I tried copying geckodriver itself into a folder within the project, adding its subdirectory to the executable_path parameter for webdriver as shown in this small guide, and finally deploying to Scrapinghub again, but I still get the same error.
I would like to know how to add geckodriver to "PATH" on Scrapinghub (if possible) and whether there are other ways I can achieve this or not. I have read something about Python eggs but I am not sure that is something that would help me with this.
I use Windows 10 and python 2.7.

Distributing py program involving PhantomJS

I have a Python program that works with Selenium and PhantomJS, and I’d like to distribute it. The functionality is quite simple; it goes onto a website, fills certain forms and returns the outcome, without any visible browser action.
The problem is that I can’t expect an arbitrary user to have PhantomJS installed on their computers. How should I approach the distribution process?
I already checked Setuptools and PythonAnywhere, but I don’t think they work for what I want.
Edit: May be too hopeful, but I'd like to be able to distribute it for Windows, OSX and Ubuntu.
The way I do it is through a web application built on Flask (one of many great python web frameworks) and hosted on PythonAnywhere.
To use PhantomJS and Selenium in PythonAnywhere you have to ask for Docker Consoles. Instructions here: https://www.pythonanywhere.com/forums/topic/1320/

using google chrome's downloader - python 3

I'm trying to download files using python 3. I use webbrowser.open_new(url) to open file locations. some files are downloaded automatically by chrome's downloader, and some are just opened in a chorme window. How can I choose between the options?
You cannot influence that, not with the Python webbrowser module.
What is downloaded and what is displayed in the browser is a preference set in the browser itself.
You could try and set those preferences using Selenium, see Set chrome.prefs with python binding for selenium in chromedriver. This is not going to be simple; you'll need to figure out the exact preference strings to alter. Perhaps the Chromium prefences list can be used as a guide there.
The Web server on which the file is hosted sends a header that suggests to the browser how it might handle the file, and the user's preferences hold some sway as well. You likely won't be able to override it easily.
You can avoid this by not using a Web browser from Python. urllib2 or better yet, the third-party requests module is a much easier way to talk to the Web.

Categories

Resources