selenium .get method fails to load a link - python

so I have started working on selenium, and this is my first time working with it, the code provided below opens chrome but doesnt open the url mentioned in the .get function.
from selenium import webdriver
import time
# open chrome and access the page
driver = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chrome.exe")
driver.get('https://dex.onxrp.com/?project=XREEFS')
time.sleep(5)
driver.close()
I have installed the selenium pip library, do i need something else as well for it to load the link?

Using selenium3 the default argument which can be passed within webdriver.Chrome() is the value of the KEY executable_path i.e. the logical/absolute path of the ChromeDriver executable but not of google-chrome executable.
Solution
Ideally, your line of code will be:
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')

Related

Chrome crashes when selenium launches a website

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

Adding extension through selenium firefox profile success. But when I open these Firefox manually, the extension still not installed

I use selenium python. My code work success, the extension was added. But when I close the code, open the Firefox Profile which added extension by manually then the extension isn't installed.
My code
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
try:
path = "My_profile_PATH"
fp = webdriver.FirefoxProfile(path)
driver = webdriver.Firefox(firefox_profile=fp)
# path to your downloaded Firefox addon extension XPI file
extension_path = "MY_extension_PATH"
# using webdriver's install_addon API to install the downloaded Firefox extension
driver.install_addon(extension_path, temporary=True)
# Opening the Firefox support page to verify that addon is installed
driver.get("about:support")
# xpath to the section on the support page that lists installed extension
addons = driver.find_element(By.XPATH,'//*[contains(text(),"Add-ons") and not(contains(text(),"with"))]')
# scrolling to the section on the support page that lists installed extension
driver.execute_script("arguments[0].scrollIntoView();", addons)
# introducing program halt time to view things, ideally remove this when performing test automation in the cloud using LambdaTest
print("Success. Yayy!!")
time.sleep(20)
except Exception as E:
print(E)
finally:
# exiting the fired Mozilla Firefox selenium webdriver instance
driver.quit()
# End Of Script
When you ask Selenium to use a profile, it copies it to a temporary location and use this copy. So whatever you do doesn't affect the original profile.
If you want your script to affect the original profile, don't ask Selenium to use a profile. Instead, tell Firefox directly which profile to use:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('-profile')
options.add_argument('/path/to/your/profile')
driver = webdriver.Firefox(options=options)

Selenium with Firefox or Chrome profile

I am trying to load a profile to selenium so that I don't have to keep log in to the website that selenium is about to visit. I am running it with Python on my Mac.
In the Firefox version, I use the below code:
def create_selenium_FF():
profile = webdriver.FirefoxProfile('/Users/Victor/Library/Application Support/Firefox/Profiles/z3ay0enb.default')
driver = webdriver.Firefox(profile)
return driver
It can successfully start Firefox, but it doesn't have the log in info of the website that it visits, however I check in the automated Firefox browser using about:profiles, it does recognise the profile that I feed it.
In the Chrome version, I use the below code, notice I make a local copy of the profile already.
def create_selenium_chrome():
DRIVER = 'chromedriver'
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/Users/Victor/Library/Application Support/Google/Chrome2")
options.add_argument("--profile-directory=Default")
driver = webdriver.Chrome(DRIVER, options=options)
return driver
It can also start Chrome, and looks like it has my profile, but it raises an error:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
How can I get it working please?
I just solved the problem !
So here is my code :
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\%username%\\AppData\\Local\\Google\\Chrome\\User Data 2")
driver = webdriver.Chrome(executable_path=path,options=options)
driver.get("https://www.google.com")
The thing is, you'll get this error if there already is chrome opened on your computer !
So, i just copy / paste the folder User Data and rename the pasted one into User Data 2 so my chrome works with user data and selenium with user data 2 I guess.
I know that you've been waiting for a long time and I don't know if u still need this but here you got !!

ChromeDriver crashes with dialog-box prompt - Chromedriver stopped working

After running pip selenium and downloading chromedriver.exe to C:/chromedriver/chromedriver.exe directory. Running my program results in Chrome not being able to open the URL and the following message prompts in a dialog-box:
Chromedriver stopped working
This is my attempt at testing that the source-page could be accessed.
import requests
from selenium import webdriver
Base_url = "https:/www.facebook.com"
driver = webdriver.Chrome(r'C:/chromedriver/chromedriver.exe')
driver.get(Base_url)
print (driver.page_source)
Can someone help me sort this out?
Thank you.
To open Chrome Browser using chromedriver binary you need to pass the argument executable_path along with the absolute path of the chromedriver binary and invoke the proper url as follows :
from selenium import webdriver
Base_url = "https://www.facebook.com/"
driver = webdriver.Chrome(executable_path=r'C:/chromedriver/chromedriver.exe')
driver.get(Base_url)
print (driver.page_source)

Open Chrome but just get data in URL address want it to be google.com

This is the code I use:
import time
from selenium import webdriver
driver = webdriver.Chrome('C:/Program Files (x86)/Google/Chrome/Application/chromedriver') # Optional argument, if not specified will search path.
driver.navigate().to("http://www.google.com")
The URL I get in Google is data; I have selenium installed and Chromium. I don't know if I missed something. I tried with get driver a lot and it doesn't work.
You need to use
driver.get(url)

Categories

Resources