how to find and click a button with selenium python - python

I'm pretty new to programming.So i have this code its supposed to log me in at instagram but i doesnt works.
I tried to find it by x_path and other methods but didnt get it right.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import webbrowser
driver = webdriver.Chrome()
webbrowser.open('https://www.instagram.com/accounts/login/')
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-infobars")
browser = webdriver.Chrome(executable_path =
"C:\chromedriver",chrome_options=chrome_options)
browser = webbrowser
login_elem =
webbrowser.find_element_by_xpath('//article/div/div/p/a[text()="Anmelden"]')
login_elem.click()
driver.find_element_by_css_selector('.button.c_button.s_button').click()
ese.clickButton(Anmelden)

Related

Selenium closes browser right after opening

I am trying to open Brave using Selenium (in Python). It actually opens but then immediately closes with the following errors appearing in the console:
[23340:9252:1107/063438.209:ERROR:os_crypt_win.cc(93)] Failed to
decrypt: The parameter is incorrect. (0x57)
[23340:9252:1107/063438.210:ERROR:brave_sync_prefs.cc(114)] Decrypt
sync seed failure
DevTools listening on
ws://127.0.0.1:53809/devtools/browser/ecce3b0e-2884-4173-bdab-2215a3d7f507
[23340:9252:1107/063438.480:ERROR:CONSOLE(1)] "[Shields]: Can't
request shields panel data for tabId: 2. Error: No tab url
specified", source:
chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd/out/brave_extension_background.bundle.js
(1)
I've done some searching but couldn't really find anything helpful.
Here is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
service = Service("C:/Auxiliary/chromedriver_win32/chromedriver.exe")
options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
self.driver = webdriver.Chrome(service=service, options=options)
self.driver.get("https://google.com")
Selen()
I'm using Windows 11.
Firstly, do you have chrome installed, and secondly, does it work if you do this?
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path, options=options)
self.driver.get("https://google.com")
time.sleep(20)
driver.close()
instance = Selen()
If it does work, try this to get it to work with brave,
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path, options=options)
self.driver.get("https://google.com")
time.sleep(20)
driver.close()
instance = Selen()

Python - Cannot login to any site with google account using selenium webdriver

Here is what it shows me when I try to log in:
What options.add_argument arguments should I use?
My code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import time
url = "url"
options = Options()
options.add_argument('--no-sandbox') # Bypass OS security model
options.add_argument("--window-size=1360,768")
driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=options)
driver.get(url)

Why does headless in python selenium with Chromium not work?

I'm try to run a code on my Raspberry Pi headless. In normal mode it works totally fine, but if I try to make it headless the code "ignores" it.
I tried different ways of headless, with -- or without , it didn't changes anything.
My current code looks so:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument ("-headless")
options.add_argument ("-disable-gpu")
allesFertig = True
driver = webdriver.Chrome(options = options, executable_path ='/usr/lib/chromium-browser/chromedriver')
driver = webdriver.Chrome()
Any ideas to fix it ?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument ("headless")
options.add_argument ("disable-gpu")
allesFertig = True
driver = webdriver.Chrome(options = options, executable_path ='/usr/lib/chromium-browser/chromedriver')
just remove second driver , you are creating chrome instance again without options thats why its opening GUI

I can't load my chrome profile by selenium

from selenium import webdriver`
import time
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\avayn\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path=r'E:\chromedriver_win32\chromedriver.exe', chrome_options=options)
#options.add_argument("--disable-extensions")
driver.get("https://www.ea.com/tr-tr/fifa/ultimate-team/web-app/")
time.sleep(15)
transfer = browser.find_element_by_xpath("/html/body/main/section/nav/button[3]").click
Normally, I can login automatically, but my chrome profile is not loading.

How to start Chrome with webdriver and quic disabled?

I need to start chrome with webdriver with quic disabled as follow:
--flag-switches-begin --disable-quic --flag-switches-end
I am using python with selenium 2.47.3
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
options = webdriver.ChromeOptions()
options.add_argument("--disable-quic")
_browser = webdriver.Chrome(chrome_options=options)
Doing that does not put --disable-quic in between --flags-switches-begin and end.
In case anyone is still looking for this, the correct way to do this is:
options = webdriver.ChromeOptions()
options.add_argument("disable-quic") # not "--disable-quic"
_browser = webdriver.Chrome(options=options)

Categories

Resources