Allow connection selenium Standalone server with python scripts - python

I've write a script in python for a bot that run using selenium, untill now I used the normal selenium webdriver, but now I want to move to Selenium Standalone server.
I have 2 servers on DigitalOcean, I want to use one server as the selenium standalone server and the other for send the requests.
In the Main server I run java -jar ~/selenium/selenium-server-standalone-3.14.0.jar for run the Selenium server, and it works.
In the second I have my scripts but I can't figure out how to allow the connection.
My options for run the webdriver are:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('user-data-dir=/var/www/users/'+ Setup.db +'/cookies')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--lang=en')
chrome_options.add_argument('CHROME')
browser = webdriver.Remote(command_executor='http://MAIN_SERVER_IP:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)
But I can't run the webriver, I see that the 2 servers are "talking" beacause when I try to run the script, in the main server I read Only local connections are allowed. so that mean that there are some problem with the firewall or the settings but I don't know what to do.

Related

Selenium Firefox Not Working When Disconnected From Remote Desktop (RDP)

I am automating a process using Selenium Firefox and Python. I am running Selenium on a Google Virtual Instance and accessing using RDP. All went fine when I ran it through RDP, but the problem is when I disconnect from RDP, Selenium doesn't work.
The part of selenium that doesn't work is :
WebDriverWait(driver, 15).until(ec.element_to_be_clickable((By. CSS_SELECTOR,'div.van-key__wrapper:nth-child(9) div:nth-child(1)'))).click()
I have tested everything all over the internet like gpedit regedit everything and also not tell to put bat file or command to stay connected to local user like chromedriver (selenium).

Not working while Selenium in Google colaboratory(no new chrome pop up)

I have a trouble in Selenium on Google Colaboratory.
I have tried to auto-login for a portal site in my country.
I learned that when I run the code, then new chrome window should be opened.
But I ran the code below, nothing happened even without error message.
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
wd.get("https://nid.naver.com/nidlogin.login")
sleep(0.5)
wd.find_element_by_name('id').send_keys('ID')
sleep(0.5)
wd.find_element_by_name('pw').send_keys('password')
Running finished but I didn't have any results...
How can I get a new window?
Google Colaboratory runs code on server and Chrome runs on server too - so Chrome can display only on monitor connected to this server and you can't see this monitor. And there is no option to redirect image from server's monitor to your monitor - to Google Colaboratory's window on your monitor.
If you will run it on your computer then you will not see Chrome because you use the option "--headless" which means "not display window". It is often used on servers because the server usually doesn't have a monitor (server is called "headless server" because the monitor looks like a computer's head), and the user couldn't see this monitor.
With option "--headless" Chrome doesn't have to render and display page so it may also work faster. This option can be useful even on a local computer.

Run Selenium Python Script on Remote Server

I've built a web scraper using Selenium that I need to run when my local machine is sleeping and not connected to a network. I have a remote server that I can use to run this script, but I'm having a hard job conceptualizing how this will work. Can I use Selenium's remote driver to do this? I have it installed on my local, do I need to install anything on my server?
Here's an example of the start of my script which runs great on my local:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from twilio.rest import TwilioRestClient
import sys
# driver = webdriver.Chrome()
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME)
driver.get("http://www.southwest.com")
Does your code resides on remote server? Do you want to execute tests on remote server or local machine? Where is your node?
keep your code on remote server -> make it(remote) hub -> register node of your choce where you want to execute test cases -> create a jenkins job for this which will enable to execute on demand.

ChromeDriver Does Not Open Websites

I am experiencing a very strange behaviour when testing Chrome via selenium webdriver.
Instead of navigating to pages like one would expect the 'get' command leads only to the download of tiny files (no type or.apsx files) from the target site.
Importantly - this behavior only occurs when I pass chrome_options as an argument
to the Chrome driver.
The same testing scripts work flawless with firefox driver.
Code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options # tried with and without
proxy = '127.0.0.1:9951' # connects to a proxy application
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('whatismyip.com')
Leads to the automatic download of a file called download (no file extension, Size 2 Byte).
While calling other sites results in the download of small aspx files.
This all happens while the browser page remains blank and no interaction with
elements happen = the site is not loaded at all.
No error message, except element not found is thrown.
This is really strange.
Additional info:
I run Debian Wheezy 32 bit and use Python 2.7.
Any suggestions how to solve this issue?
I tried your code and captured the traffic on localhost using an SOCKS v5 proxy through SSH. It is definitely sending data through the proxy but no data is coming back. I have confirmed the proxy was working using Firefox.
I'm running Google Chrome on Ubuntu 14.04 LTS 64-bit. My Chrome browser gives me the following message when I try to configure a proxy in its settings menu:
When running Google Chrome under a supported desktop environment, the
system proxy settings will be used. However, either your system is not
supported or there was a problem launching your system configuration.
But you can still configure via the command line. Please see man
google-chrome-stable for more information on flags and environment
variables.
Unfortunately I don't have a man page for google-chrome-stable.
I also discovered that according to the selenium documentation Chrome is using the system wide proxy settings and according to their documentation it is unknown how to set the proxy in Chrome programmatically: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy

Selenium Remote Web Driver: How to start the remote server from Client

I have few questions in Selenium WebDriver (Selenium2) :
My 1st question is, do I need a standalone .jar file for RemoteWebDriver?
My 2nd question is, if the standalone .jar file is needed, then how can I start this .jar file/Selenium Server from the WebDriver's Client side (just like in Selenium RC) using Python ?
I do know how to start the selenium server from command line locally. But I was wondering if WebDriver has any improvements from RC regarding starting the Server. I am also aware that there is no need of a Selenium Server (standalone .jar file) if WebDriver is used locally.
Yes standalone jar file need to be in running state, in order to run tests on remote machine using RemoteWebDriver.
To run the server, just use java -jar that probably you know already.
refer: http://code.google.com/p/selenium/wiki/RemoteWebDriver for more details.

Categories