Why selenium crashes when I set google chrome profile? [duplicate] - python

This question already has answers here:
Selenium: Point towards default Chrome session
(2 answers)
How to open a Chrome Profile through --user-data-dir argument of Selenium
(3 answers)
How to use Chrome Profile in Selenium Webdriver Python 3
(12 answers)
Closed 3 years ago.
So thats my code, I want to open chrome with my default profile information in selenium. but its doesn't load and crashes when I click on profile icon in chrome
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/Users/Library/Application Support/Google/Chrome/Default/Default")
driver = webdriver.Chrome(executable_path='/Users/Desktop/supbot/chromedriver', options=options, service_log_path="/tmp/log")
driver.get('google.com')

You should use full path to the driver file like:
C:\pathtodriver\chromedriver.exe
Also, avoid using Capabilities, try this approach:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get('google.com')

Related

Selenium for Python opens chrome tab with "data" rather than specified URL [duplicate]

This question already has answers here:
Selenium doesn't open the specified URL and shows data:,
(2 answers)
Closed last year.
My chromedriver and chrome app are the same up to date version, but the tab still just opens to "data" in the URL bar
driver = webdriver.Chrome(executable_path="C:\\Windows\\chromedriver.exe")
driver.get("https://google.com")
Driver instance can be simply:
driver = webdriver.Chrome(r'path\to\chromedriver.exe')
Is chrome and driver at last version?
The syntax is ok, try to change chromedriver path.

im trying to save cookies so that next time i log in i wont have to sign in again but its just giving me an error [duplicate]

This question already has answers here:
How to save login data to be recognized for Python Selenium webdriver
(2 answers)
Error when loading cookies into a Python request session
(6 answers)
Closed 2 years ago.
import pickle
import selenium
from selenium import webdriver
import selenium.webdriver
import options
path = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(path)
chrome_options = Options()
chrome_options.add_argument("user-data-dir=selenium")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("http://www.google.com")
the error that i am getting is: NameError: name 'Options' is not defined
am i doing soomething tottaly wrong. im trying to save the cookies so that next time i can login in to my whatsapp without having to manualy do the qr code

how to scrape a dynamic website without selenium [duplicate]

This question already has answers here:
Can a website detect when you are using Selenium with chromedriver?
(25 answers)
How to find the $cdc_ (chromedriver params) in website?
(1 answer)
Selenium Webdriver can't access a website (The requested URL was rejected)
(1 answer)
Closed 2 years ago.
i am facing an issue that i hope anyone can help me with.
i'm trying to scrape a webpage using selenium package on python but it keeps detecting that i'm using selenium and redirects me to a log in page that i can't use.
i tried using a fake agent but it still detected me, i tried changing the "$cdc" in the chrome driver but it still didn't work. apperciate if anyone can help me.
here is the code i'm using :
options = webdriver.ChromeOptions()
ua = UserAgent()
userAgent = ua.random
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument("--window-size=1920,1080")
options.add_argument('enable-automation')
options.add_argument(f'user-agent={userAgent}')
#options.add_argument('--headless')
driver = webdriver.Chrome()
driver.get("https://www.mcmaster.com/nuts/hex-nuts/medium-strength-steel-hex-nuts-grade-5/")

How to let webdriver.Firefox() open minimized? [duplicate]

This question already has answers here:
How to make Firefox headless programmatically in Selenium with Python?
(7 answers)
Closed 2 years ago.
I have this code:
from selenium import webdriver
driver = webdriver.Firefox()
But how can I let the browser open up minimized or hidden?
The headless property will do the task for you. Import Options() from selenium.webdriver.firefox.options
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
my_opt = Options()
my_opt.headless = True
driver = webdriver.Firefox(options=my_opt, executable_path=r'path_to_your_geckodriver')
driver.get("url_you_want_to_access")
All set!

Selenium / Python switch webdriver from headless to window mode [duplicate]

This question already has answers here:
How do I make Chrome Headless after I login manually
(2 answers)
Closed 4 years ago.
Is there any way to switch Chrome webdriver from headless mode to window mode?
One thing that came to my mind is to 'switch' existing web driver to non-headless mode.
Another idea: to create new instance of webdriver (this time non-headless) with some sort of 'state' from old one so the user operations can be executed. I don't know how to do or if it is possible though.
import os
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException,
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(
executable_path=os.path.join(os.getcwd(), 'chromedriver'),
chrome_options=options,
)
driver.get('https://website.com')
try:
driver.find_element_by_xpath('//h1').click()
except NoSuchElementException:
print('You have to click it manually')
# here I need Chrome browser
# to be opened so that I can click a link
print('The name of this thing is: ', end='')
print(driver.find_element_by_xpath("//h1[#class='name']").text)
If you need to open a new tab
driver.execute_script("window.open()")
If you need to switch to this new one
driver.switch_to.window(self.driver.window_handles[1])
Then you get the page
driver.get('https://website.com')
and the end you can close it (the new one)
driver.close()
and you back to the first driver
switch_to.window(driver.window_handles[0])

Categories