Python Selenium with Safari Webdriver crashes after loading website - selenium

I've been trying to use safari with selenium. With the latest update, it does not need the prev selenium safari webdriver. However, when I run the below code, it crashes after loading the site. I've restarted my mac and all. Tried thinking of the problem but got nowhere. The code is very simple and I already did the necessary actions on the options such as ticking "allow web automation" and other things. Anyone can help?
from selenium import webdriver
class Instabot:
def init(self):
self.driver = webdriver.Safari()
self.driver.get("https://google.com")
Instabot()

Related

New error discovered when using Chromedriver Selenium

When I try to open Chrome with selenium with webdriver, it shows a chrome that looks like this.
Even though it's been a long wait, it's still the same. While I open it by right clicking, it works fine.
I've tried using all versions of Chromedriver 100 and 99, but the results haven't changed much.
Here is the source code that I use:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f"--user-data-dir=G:\\Multi_Chrome\\testing\\Data\\profile")
driver = webdriver.Chrome(service=Service("D:\\Python\\Project\\chromedriver.exe"),
options=chrome_options)
input("Press any key to coutinue ...")
driver.close()
driver.quit()
Any ideas? By the way, I want to ask more, how to open a normal portable chrome. Instead of right clicking and choosing open. Is there a way to automatically open it?
I have partially mentioned it in this article: Open a complete portable chrome like regular Chrome
your question isn't clear because you didn't mention what is the error, but as I see in the screenshot you have already opened one chrome browser before you run the script, but you use --user-data-dir=G:\\Multi_Chrome\\testing\\Data\\profile it means that this profile is already is in use so you cant open another chrome browser with the same profile. so The simplest and easiest fix is to close all running chrome browsers and after that try to run your script again

Chomedriver selenium doesn't work under vpn

I encountered an issue rather strange. When I run python scripts with selenium under fortinet vpn they get stuck. It never gets past "data:," at the address bar. How fortinet detects chromedriver?
Example code:
from selenium import webdriver
browser = webdriver.Chrome('/usr/local/bin/chromedriver')
browser.get('https://www.google.com/')
No VPN:
https://i.stack.imgur.com/IFBF1.png
with VPN:
https://i.stack.imgur.com/WcE0W.png
update 1
Tried modifying _cdc as suggested in this question but had no progress:
Can a website detect when you are using selenium with chromedriver?
update 2
Just tried using Firefox and Safari. Both work fine under the VPN. It definitely blocks chromedriver on some way.

Running chrome via selenium

I did it earlier but I can't use chrome via selenium now. Browser opens for a few seconds then closes and then I got an error (about 5 minutes later):
Message: session not created
from disconnected: unable to connect to renderer
(Session info: chrome=70.0.3538.67)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.18.14-arch1-1-ARCH x86_64)
I use following code for running browser (which I always use):
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
opts = Options()
browser = Chrome(options=opts)
Chromedriver directory is in the PATH. Versions of chrome and chromedriver you can see in the error. Python 3.7.0, selenium==3.14.0. What's wrong in my actions?
P.S. BTW, It works fine with Firefox
Your versions look compatible with each other based on the compatibility list, so I don't think it has to do with that. I have not seen those options used in that way before though.
Please try this:
from selenium import webdriver
ChromeOptions = webdriver.ChromeOptions()
browser = webdriver.Chrome(chrome_options=ChromeOptions)
browser.get("https://www.google.com")
browser.quit()
Let me know if that is able to open your browser. If it is, then I am assuming you are having issues with some of the options you are passing chrome.
If you are still have issues after checking all the options you are passing chrome, try rolling back your chromedriver version HERE to 2.42. It should still be compatible with chromer version 70.-.
I am on the same versions as you, and I'm not experiencing this issue.
A couple other things to think about:
Are you using headless chrome? If so switch to non-headless and test.
Make sure to close out of all instances of chromedriver before updating with another version.
If chrome recently updated, or you recently updated your driver, try
restarting the machine.
Actually I don't know why, but it works fine now. Everything I did are recommendations from the answer above. It didn't work right after my actions but now it's okay

Firefox runs in background in Selenide

usually, questions are in opposite way, how to make a Firefox run to be in the background. I have written some time ago some basic tests in Selenide, but when today I tried to run it (as usual) on a server, I got an error
SessionNotCreatedException
I started to look for the result and I noticed, that when I'm running now tests locally from my computer, Firefox does not appear. I can see Firefox's tasks in Task manager, I got an error with a done screenshot, but the browser does not open.
I noticed there is plenty of questions about how to run tests with the headless option, but I need something opposite, this might be a problem with SessionNotCreatedException, the server does not see the browser.
As I know Selenide runs the newest gecko driver (it's updating). I tried to set some options in the beginning:
FirefoxOptions options = new FirefoxOptions();
options.setCapability("marionette", false);
options.setCapability("headless", false);
and also updated Selenide to 5.0.0, but it's still failing
EDIT: I can't use any other browsers
For running tests on a server generally, the server is an X window system so the way to do it is to run a virtual display.
Using Xvfb is the best way for that! you can read about it here.
from xvfbwrapper import Xvfb
with Xvfb() as xvfb:
# launch virtual display here.
# start your webdrivr in the virtual display
Or you can use PyVirtualDisplay link here.
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Firefox will run in a virtual display.
# you will not see the browser.
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()
Note
Make sure your server is an X Window System!
As you can see here it doesn't work on windows.
Hope this helps you!

Selenium Testing Safari Extension

When you attempt to run Selenium tests in a scripting context whose origin is at "safari-extension://...", the session hangs. I believe the problem is caused by extension sandboxing, which means if I get Selenium running in the same origin as the extension I am testing, it should be possible to execute selenium commands in my extension.
Question: Can I incorporate the Safari Driver into my Safari extension during testing to circumvent sandboxing?
We modified the Safari driver to navigate extension:// pages, and the problem persists. It looks like Apple blocks Selenium at the extension level :(