In order to perform the testing I have to open the Chromium Browser. But When i use
driver = webdriver.Edge('msedgedriver.exe')
driver.get('https://xxx.service-now.com/')
it is taking me to the sign-in page.
But when i normally open 'xxx.service-now.com' it takes windows authentication and takes me to the service-now page directly.
This is my normal Chromium Window
and this is my Chromium Window when i am opening using Selenium
I want to open the normal Chromium using selenium, as it will automatically sign me in.
Your help will be appreciated.
After doing some experiments i got the answer.
import selenium, getpass
from selenium import webdriver
from msedge.selenium_tools import Edge, EdgeOptions
user = getpass.getuser()
options = EdgeOptions()
options.use_chromium = True
options.add_argument("user-data-dir=C:\\Users\\" + user + "\\AppData\\Local\\Microsoft\\Edge\\User Data")
driver = Edge('msedgedriver.exe',options = options)
driver.get('https://xxx.service-now.com/')
This has resolved my issue.
Related
When I run this code, the page opens and closes. I can't reach the page. Everything is in the latest version. I am a Windows user.
I was trying to open Instagram page with this code.
enter image description here
I tried to open the instagram site with this code and the site was closed as soon as it was opened.
Im not familiar with selenium but I know for a fact that
get() just gets the HTML code of the website and does not display it
You have to add the below Chrome Option:
options.add_experimental_option("detach", True)
Full code:
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(chrom_driver_pat), options=options)
driver.get(<url>)
Next time, don't post the image, post the code and explain your issue clearly.
First of all, please, do not use images when your want a code review or help, it is more easier to help with raw code.
Selenium now uses Service method to run webdriver.
To run what you want, you need to fix some parts of your code, like this:
from selenium import webdriver
# in my case, i'm using selenium==4.5.0, for this version, is necessary to
# use selenium.webdriver.chrome.service to use driver path
from selenium.webdriver.chrome.service import Service as ChromeService
# For Windows path, use r"C:\..." when you will use \
# Remember to set the executable file too
chrome_driver_path = r"C:\pythondriver\chromedriver\chromedriver.exe"
# you can use "universal" path too, like linux, using / instead of \
# chrome_driver_path = "C:/pythondriver/chromedriver/chromedriver.exe"
# instead using:
# webdriver.Chrome()
# driver = webdriver.Chrome(chrome_driver_path)
# use this:
chrome_service = ChromeService(chrome_driver_path)
driver = webdriver.Chrome(service=chrome_service)
url = "https://instagram.com"
driver.get(url)
I tested using the configurations below and worked for me:
Chromedriver - 108.0.5359.71
Chrome - 108.0.5359.125 - 64 bits
If you need more help using Chrome Service, try look the Selenium Docs
I'm trying to open a Firefox browser with undetected_chromedriver.
But only getting a default Firefox browser instead of getting the url I provided.
What did I miss or do wrong?
Here is the code I made so far.
import undetected_chromedriver as uc
import time
if __name__ == '__main__':
driver_path = "C:/Users/jay/Desktop/py/geckodriver.exe"
Firefox_path = "C:/Program Files/Mozilla Firefox/firefox.exe"
option = uc.ChromeOptions()
option.binary_location = Firefox_path
driver = uc.Chrome(executable_path=driver_path, options=option)
driver.get('https://google.com')
time.sleep(10)
I'd appreciate it if you could help me with this.
undetected_chromedriver is ONLY for chromedriver.
It modifies values directly inside binary file chromedrive.exe and it doesn't know how to modify values inside file geckodriver.exe.
See also repo GitHub - undetected-chromedriver.
There is:
"Works ... on .... Chromium based browsers".
"Automatically downloads the driver binary and patches it."
It means it automatically uses chromedrive.exe and it can't even use geckodriver.exe. And chromedrive.exe doesn't know how to communicate with Firefox - so it can't open page.
You can use it only with browsers which use engine Chromium - like Brave and maybe Opera, Microsoft Edge (but I didn't test it).
I would like to log into a website and download a file. I'm using selenium and the chromedriver. Would like to know if there is a better way. It currently opens up a chrome browser window and sends the info. I don't want to see the browser window opened up and the data being sent. Just want to send it and return the data into a variable.
from selenium import webdriver
driver = webdriver.Chrome()
def site_login(URL,ID_username,ID_password,ID_submit,name,pas):
driver.get(URL)
driver.find_element_by_id(ID_username).send_keys(name)
driver.find_element_by_id(ID_password).send_keys(pas)
driver.find_element_by_id(ID_submit).click()
URL = "www.mywebsite.com/login"
ID_username = "name"
ID_password = "password"
ID_submit = "submit"
name = "myemail#mail.com"
pas = "mypassword"
resp=site_login(URL,ID_username,ID_password,ID_submit,name,pas)
You can run chrome in headless mode. In which case, the chrome UI won't show up and still performing the task you were doing. Some article I found on this https://intoli.com/blog/running-selenium-with-headless-chrome/. Hope this helps.
First option: If you are able to change the driver, you can use phantom-js as driver. That was a headless browser and you can use it with selenium.
Second option: If the site are not dynamic (easily called it SPA) or you are able to trace packet (which can be done in chrome dev tools), you can directly use request with the help of beautifulsoup if you need to get some data on the page.
Just add this two lines
chrome_options = Options()
chrome_options.add_argument("--headless")
This should make chrome run in the background.
I am on Mac OS X using selenium with python 3.6.3. Im using this code, but browser Google chrome closes immediately after being launched with selenium I start this code, Google chrome opens new windows with Default profile, but chrome wont open the url google.com.
Whats problem with code? Thanks for the help!
FILE_NAME_PROFILE = '/Users/User/Library/Application Support/Google/Chrome'
options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir='+FILE_NAME_PROFILE)
driver = webdriver.Chrome('assets/chromedriver', chrome_options=options)
driver.get("https://google.com")
I am using two arguments and work well in development
"user-data-dir=C:\Users\NameUser\AppData\Local\Google\Chrome\User Data"
"profile-directory=Default"
If you want use another profile (not default) you have to create it and only you have to change the second argument. All profiles are stored in 'User Data' folder
"profile-directory=Profile 1"
I'm trying to teach myself some python and I've been working on a project which uses selenium to open firefox and interact with netflix but I need to enable 'Play DRM' to stream, I dont see it in 'set_preferences' and I cant inspect element on the contents page in preferences so I'm not sure how to enable it.
import time, pyautogui, os
from selenium import webdriver as wd
from selenium.webdriver.common.keys import Keys
profile = wd.FirefoxProfile()
ntfx='http://www.netflix.com/'
driver=wd.Firefox()
driver.get(ntfx)
url = driver.current_url
Took 4 days but finally came with a solution
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addPreference("media.eme.enabled",true);
firefoxOptions.addPreference("media.gmp-manager.updateEnabled", true);
Then add the firefoxOptions to the driver
Ok looked more into the Firefox Profiles and made a custom profile as show here. I went into preferences/content and enabled "Play DRM" and added the PATH to the custom profile
profile = wd.FirefoxProfile('./fire_fox_profile')
driver=wd.Firefox(profile)
As alternative solution of using firefox profiles you can do
driver.get('about:preferences')
driver.find_element_by_id('playDRMContent').click()
The method of #RonanB worked for me
Just go into about:profiles in firefox
then under the DRM enabled profile, look for the root directory. For me it was : /home/myusername/.mozilla/firefox/14iw27z4.default-release
so like this :
myProfile = webdriver.FirefoxProfile('/home/myusername/.mozilla/firefox/14iw27z4.default-release')
driver = webdriver.Firefox(myProfile)
First time answering any question on stackoverflow
This little trick worked for me so what i did was
First make sure normal firefox(i.e when not launched using selenium or firefox) is able to play drm video.
Next, i created new firefox profile named 'selenium' and launched firefox with selenium profile.
To create firefox profile run 'firefox -p' command in windows run program. picture for ref
Now in 'selenium' profile firefox session go to drm video site. Firefox downloaded some drm playing content and after some time drm video played.
then i launched firefox with this code:-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
profile = webdriver.FirefoxProfile(r"C:\Users{USER}----PATH TO SELENIUM PROFILE FOLDER----")
print('lll')
driver = webdriver.Firefox(profile, executable_path=r'-------------\firefox\geckodriver.exe')
url = 'http://amp.azure.net/libs/amp/latest/samples/videotag_multiDRM_PlayReadyWidevineFairPlay_notoken.html'
driver.get(url)
and my drm video played,
Now this worked for me not sure will work for you
tested on:-
Firefox Version 92.0(64-bit)
gechodriver version geckodriver-v0.29.1-win64