Chrome crashes when selenium launches a website - python

I am trying to open a website on chrome via selenium with the following code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s=Service('C:/Users/Morteza/Documents/Dev/chromedriver.exe')
browser = webdriver.Chrome(service=s)
url='https://www.google.com'
browser.get(url)
link to problem: https://share.cleanshot.com/p1qu5y

This is not an issue or crash. After the specified actions are completed successfully, selenium closes the web browser. This program works fine.
Use the following code with a while True block
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)

This isn't any crash or an error as such. Selenium automatically closes the client i.e. the Chrome Browser instance after executing the last line of your code. However this practice may accumulate undeleted/zombie chromedriver instances within your system.
Ideally, you always need to invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully at the end of your tests.

the chromedrive path in your code, i guess your platform is windows.
but the picture you post revease that your machine is mac.
pay attention to the chromedriver file PATH and your PC platform, make sure they suit to each other.
or you could put chromedriver in system PATH variable, so you do not need to specify the chromedrive path in your code

Related

Selenium closes after it opens

So I'm using Python 3.9.5
Everytime I use the driver.get function, chrome appears for a second and then immediately closes the window. How do I make it like it stays open? It used to work, but when I closed VSCode and re-opened it, I did something that made it so that chrome doesn't appear to be opened.
I think you can solve this by adding the detatch option.
For example:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
Check the logs for more information. Sometimes your web browser has been updated and the chromedriver does not match with the version, so, you have to download the specific version of your browser.

how to run Selenium ChromeDriver with cookies from actual Chrome installation?

I want to use Selenium(python) to log in to several sites and I need to get all my Chrome cookies,
How should I do this?
This is a duplicate question, anyways:
Do the following:
# Remember to import
from selenium.webdriver.chrome.options import Options
options = Options()
# Your user agent
options.add_argument("YOUR_USER_AGENT")
# Path to chrome application
options.add_argument("CHROME_APPLICATION_PATH")
# Path to chrome driver
driver = webdriver.Chrome(executable_path="CHROME_DRIVER_PATH", options=options)
You will need to do some research about your own system and see what exactly is your user-agent (there are a million site that tell you)
As well as finding the correct path for your chrome application.
Then, proceed normally, this will execute chrome as if you opened it yourself.

How to check if chromedriver exist or running?

I am using 3rd party software to create a fancy application GUI with several buttons.
Each buttons will execute different .py file/.exe file. For instance:-
btnYahoo = execute yahoo.py/yahoo.exe
btnGoogle = execute google.py/google.exe
So inside both py scripts is using chromedriver to launch Chrome Browser and redirect to specific URLs
google.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path=r'chromedriver.exe')
driver.get("https://www.google.com")
yahoo.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path=r'chromedriver.exe')
driver.get("https://malaysia.yahoo.com/?p=us")
So if I execute both scripts above, it will launch 2 chrome browser.
Therefore, my concern is how can I check is webdriver.Chrome is running?
If so, then assign the webdriver.Chrome to a variable, so that I can open new tab and do further automate script progress.
For example of expected result:
Execute google.py - A new chrome browser is open and redirect to
www.google.com
Execute yahoo.py - If webdriver.Chrome is executed/existed, then assign the browser to driver variable. Else launch new browser
Thanks for advance information.
I was able to do so by checking if driver.session_id was None.

Selenium Ghost browser unexpected exited status 0

Browser opens and driver loses its control. It starts the browser but it can't initiate the driver in order to use it and send_keys, or do anything.
The code runs using Ghost Browser, which is a chromium based browser.
What should be done in order to selenium get control over browser?
Ive tried to get session_id in order to attach selenium to existing browser but it didnt worked also, since it cant get the session_id, because selenium exits.
Code:
exe_path = r'C:\Users\Anonymous\AppData\Local\GhostBrowser\Application\ghost.exe'
driver = webdriver.Chrome(executable_path=exe_path)
driver = webdriver.Chrome(executable_path=exe_path)
Are you sure you use chrome? Maybe change the webdriver.Chrome

Python selenium - changing a URL during the test, request is not finished and the script hangs

I have a testing scenarios which run on certain url, when i change the url the browser hangs on the changed url, no 'Finished Request' in the log.
any idea why the browser hangs? I can see that the browser is presenting the new url - all elements are presented, when I manually refresh the browser the script continues.
class ArmingScenarios(unittest.TestCase):
LogFile.logfilename
def testing_arming_scenarios(self):
driver.get(config.get('WeRURL', 'wer_url'))
Login.login(driver)
Arming.arming(self,'dashboardScreenStatusTxt',config.get('Arming','arming_button'),config.get('Arming','disarm_button'))
driver.get(config.get('WeRURL', 'history_url'))
Testing.validate_history(self,driver)
print('Pass')
If you are not running on current versions of both Chrome and chromedriver, please update to Chrome build 65 and chromedriver 2.37 HERE. To update your Chrome, go to help > About google chrome and it should update automatically. If you cannot update to current builds, try using this:
from selenium import webdriver
ChromeOptions = webdriver.ChromeOptions()
ChromeOptions.add_argument('--disable-browser-side-navigation')
driver = webdriver.Chrome('your/path/to/chromedriver.exe',
chrome_options=ChromeOptions)
Also, refer to Python - selenium webdriver stuck at .get() in a loop, for more help about .get() hang issues with selenium.

Categories

Resources