For a project of mine I decided to go with Selenium. It's a "scanner" for an web based online game, hence interaction with the page is needed. All things set and done I'm worrying for the security of my application and hence I took a look at well-known questions on SO. I found bunch of suggestions which may help securing the detectability of said programme.
What is left is something related to Chrome Plugins. In my Project File I got the chromedriver.exe and a dedicated resource folder for stuff like the cookies and settings it's supposed to run with. Now I want to run the Chromedriver.exe with Chrome Plugins.
So is there any way to download Chrome Plugins in the Chromedriver.exe and run them every time with the Selenium process?
First method is to create a chrome profile and load it with youre chrome plugins
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe",
chrome_options=options)
Read more here How to load default profile in chrome using Python Selenium Webdriver?
another method is to add it in the chrome options:
options.add_extension('./exampleOfExtensionDownloadedToFolder.crx')
To download the chrome extension, follow below steps.
add chrome extension.
Go to http://chrome://extensions/]
Enable developer mode.
Click on 'Details' of desired extension.
Click on 'Pack Extension'.
Browse extension root directory. Eg. C:\Users\Admin\AppData\Local\Google\Chrome\User Data\Default\Extensions\mooikfkahbdckldjjndioackbalphokd\3.17.0_0 ( Don't forget to sort the folders by date and select latest folder.)
Click on 'Pack Extension'.( If any error get encountered related to key browse manifest.json file from step 6 path)
Browse to extension path (Eg. C:\Users\Admin\AppData\Local\Google\Chrome\User Data\Default\Extensions\mooikfkahbdckldjjndioackbalphokd ) you will find .crx and .pem file.
Copy and paste both the files in resources folder of your project.
Below java code will help you to access the extension.
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir") + "\\src\\test\\resources\\executables\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(System.getProperty("user.dir") + "\\src\\test\\resources\\executables\\5.6_0.crx"));
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
Related
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?
Using the python + selenium chromedriver with a specific user folder to keep my cookies and settings saved with the following code:
chrome_options = Options()
chrome_options.add_argument("user-data-dir=cookies")
driver = webdriver.Chrome("C:\Python\chromedriver\chromedriver.exe", options=chrome_options)
Everything used to work well, but had to reinstall Windows 10 machine and now everytime I run the script, there is an error "Google Chrome is not able to reach the data folder for reading nor writing" (not these words exactly - translated).
I noticed that all windows folders are set to read only and am not able to change it (using admin account).The controlled folder access in windows settings is turned off.
Has anyone been dealing with the same problem?
How are you running Selenium? From Powershell/CMD?
These sometimes needs to be run as admin.. Right click => Run as Administrator.
You can create a .bat file or similiar and change the properties to always run as admin.
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 working in a web scraping project with python 3.7.
Done the code in python with selenium and chromediver.exe in windows, it's working fine.
we are adding the script in aws lambda.
the issue is we need to specify the chrome driver of Linux.
I followed the steps in https://github.com/yai333/Selenium-UI-testing-with-AWS-Lambda-Layers.
i am not using any serverless yml sript(i don't know the same).
doing the following
we have a Linux machine.
create a virtual python environment and add selenium module(as described in awshttps://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html#python-package-venv)
download chromdriver and headless into a folder(size is large, so upload to S3) add both (chrome driver and python lib) as layers.
paste the handler.py (in https://github.com/yai333/Selenium-UI-testing-with-AWS-Lambda-Layers) to a lambdahandler file.
create a sample test, and click on test.
shows error:
error message 'chromedriver' executable needs to be in path
can I upload chrome driver in S3 and show the path.
Having just fought this exact issue for a few hours, I think I can help.
Within your Lambda Layer, you need to include the chromedriver binary under /bin. Os it will look something like:
layerZip/
|- bin/
|- chromedriver
Within your lambda function's infrastructure, it will exist at /opt/bin/chromedriver. As such, we need to point our Python towards that as the executable. To get it to work, I had to add the following:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = "/opt/bin/chromedriver"
driver = webdriver.Chrome(executable_path="opt/bin/chromedriver", options=chrome_options)
I can load a Selenium Chromedriver extension in python. But I need to login in this extension in order to be able to use it. My question is how can I interact with this extension in order to login within it? The extension namely is the "Hoxx VPN".
Until I have the following code:
chop = webdriver.ChromeOptions()
chop.add_extension("D:/01_PhD/Fogadas/chromeextension/2.2.2_0.crx")
driver = webdriver.Chrome(chrome_options=chop)
Selenium Webdriver can interact with web pages only. Previously I have also tried it but unable to succeed.
See this as reference:
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/7805
You can use the Opera Webbrowser it's latest version i.e. 70+ having the in-built vpn which can be activated easily by selenium
Github have the required code to operate opera using selenium