I'm using Selenium to automate a navigation in Google Meet website for a user who can't use the keyboard. However, Google Meet won't let me enter a meeting when using Chrome in test mode. If I configure Chrome webdriver to run as a regular browser, I can navigate on the website a little but eventually I can't enter a meeting at all. Here is the python code I use to initialize Chrome as a non-test browser:
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ['enable-automation'])
browser = webdriver.Chrome()
browser.get("https://meet.google.com/some_meeting_id")
time.sleep(3)
txtName = browser.find_element_by_css_selector('#jd\.anon_name')
txtName.send_keys("user_name" + Keys.RETURN) // redirects to an error page
My next hope is to use Firefox, but when I load it from webdriver, it opens with an orange address bar, indicating that it is being run by a test tool. Is there a way to run Firefox in normal mode from Selenium (just as I did with Chrome) or, even better, is there any additional configuration I can do in Chrome webdriver to make this work?
May be try this to switch the headless mode on firefox to normal mode
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = False
driver = webdriver.Firefox(options=options)
driver.get("http://stackoverflow.com")
Related
I was trying to open the CoinGecko website in a different profile in Chrome, but when I ran the code, it didn't throw any errors and just ended without opening the browser. I was wondering if you could help me figure out what I might be missing?
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument(
r"--user-data-dir=<directory path here>"
) # e.g. C:\Users\You\AppData\Local\Google\Chrome\User Data
options.add_argument(r"--profile-directory=<Profile number here>") # e.g. Profile 3
driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()), options=options
)
# Set the URL of the website you want to open
url = "https://www.coingecko.com/"
# Open the website
driver.get(url)
Remove the line - options.add_argument("--headless"), this line will open the browser in headless mode, and the browse window will not be visible.
Is there a way to run selenium headless but have it display the window for example at the start of the application ? like:
show browser
login
do captcha
go --headless
execute tasks
Actually, this is possible.
You can peek into a headless browser by using the "--remote-debugging-port" argument in ChromeOptions. For example,
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--remote-debugging-port=9222') # Recommended is 9222
driver = webdriver.Chrome(options=chrome_options)
Then while Selenium is running, you can go to http://localhost:9222 in your regular browser to view the headless session. Your browser will display links to each tab Chrome has open, and you can view/interact with each page by clicking on the links. You'll also be able to monitor Selenium/Chrome as Selenium runs its test.
Edit: As of Chrome 100 or so, you now need to go to the link chrome://inspect to view the headless session in your browser while Selenium is running.
You'll need to do some extra configuration as well. Basically:
Check the box for "Discover network Targets"
Hit "Configure..."
Add the link "localhost:9222" to the list of servers
CREDITS: https://stackoverflow.com/a/58045991/1136132
I have coded a script to perform some actions while logged into my youtube account, using my Chrome user data folder:
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
options = Options()
options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=options)
driver.get(https://youtube.com)
driver.get_screenshot_as_file("screenshot.png")
thing = driver.find_element_by_xpath(
'someXpath')
thing.click()
It works perfectly without the line:
options.add_argument('--headless')
However, when "headless" is added as an option, the screenshot taken by driver.get_screenshot_as_file shows that chrome is prompting a login to a google account, indicating that the specified chrome profile is not being used.
If possible, I'd like to use both headless mode and use my chrome profile at the same time. Thanks for any help.
For a web-test i call an online-shop which uses a special GDPR-cookie-banner. When I call this online store in a normal chrome browser, it is loaded and displayed.
However, when I call this online store with the test software (chromedriver, Selenium, Python), it is loaded but not displayed.
What is the reason and what can I do to display this banner?
Online-shop: https://www.uwaldu.de/
Browser snapshot with normal chrome browser:
Browser snapshot with webdriver:
Not sure why you won't see the special GDPR-cookie-banner. But when I access the website using a Selenium driven ChromeDriver initiated google-chrome Browsing Context the GDPR-cookie-banner is displayed perfectly everytime.
Code Block:
options = Options()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get("https://uwaldu.de/")
Browser Snapshot:
You can enable the "reader-mode" by opening chrome://flags/#enable-reader-mode in Google Chrome.
Then, you can toggle the "reader mode" while browsing a webpage:
How to get the "reader mode" version of a web page using Selenium and chromedriver?
Not really the answer you probably want. You can enable the "reader-mode" feature by using ChromeOptions.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--enable-features=ReaderMode")
driver = webdriver.Chrome(options=options)
driver.get(url)
Then you have to toggle it somehow. The Selenium documentation is quite clear that it is for not for testing browser functionality see https://stackoverflow.com/a/49801432/839338 so you are left with using another automation tool like AutoIt https://www.autoitscript.com/site/ or Sikuli http://doc.sikuli.org/ to find and toggle the "reader-mode" menu item. I'm not sure how you go about that using scrapy.