trying to send message on whatsapp with python selenium - python

I need to open web whatsapp but it gives me Deprecation Warning
here is the code
import selenium
from selenium import webdriver
import time
driver_path = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
driver = webdriver.Chrome(driver_path)
driver.get("https://web.whatsapp.com/")
driver.maximize_window()
time.sleep(20)
driver.quit
İts not giving me anything just opens Chrome
DeprecationWarning: executable_path has been deprecated, please pass in a Service object

First you need download chromedriver - https://chromedriver.chromium.org/downloads
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
ser = Service('path_to\chromedriver.exe')
browser = webdriver.Chrome(service=ser)
browser.get('https://web.whatsapp.com/')
browser.maximize_window()
time.sleep(20)
browser.quit

You need to pass The driver_path to Service(). below should work for you.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
driver_path = r"chromdriver.exe full file path here"
service = Service(driver_path)
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(service = service, options = option )
driver.get("https://web.whatsapp.com/")
driver.maximize_window()
time.sleep(20)
driver.quit

Related

driver.get(url) not executing

I am trying to automate some web scrapping in chrome
Previously I was trying it with a different method where the chrome used to open in guest mode and it was working, here is the previous method
url = 'https://stackoverflow.com/'#Example chrome = webdriver.Chrome(ChromeDriverManager().install())
chrome.get(url)
But when I shifted the method, where the chrome would open logged in by default, it is showing problems, there is no error, but driver.get(url) is not working, infact any lines after webdriver.Chrome... are not working
Here is the code after changes
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\\Users\user\AppData\Local\Google\Chrome\User Data\Default")
url = "https://www.geeksforgeeks.org/"
driver = webdriver.Chrome(executable_path=r"C:\\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe", options=options)
print("h")
driver.get(url)
This is where you made a mistake.
driver = webdriver.Chrome(executable_path=r"C:\\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe", options=options)
you need to pass the PATH of the chrome driver Not the chrome browser installed path.
if you not sure path and your chrome browser compatibility then use below code.
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)

No error in code but Login is not working for python selenium simple script

from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login")
driver.implicitly_wait(5)
username ="//input[#placeholder='Username']"
password ="//input[#placeholder='Password']"
driver.find_element(By.XPATH, username).send_keys("Admin")
driver.find_element(By.XPATH, password).send_keys("admin123")
driver.find_element(By.XPATH, "//button[normalize-space()='Login']").click()
print("Test pass")
Above script is not having driver.close() but still chrome is getting closed automatically and login page is not opening
Not sure what mistake I am doing here
I am expecting Logged in paged after given login credentials
But chrome is getting closed instead
Add the below code and try:
from selenium import webdriver
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(<chromedriver.exe path>), options=options)
driver.get(<URL>)

How to pass cloudfire?

I have a code for making temp mail automatically but I have a problem.
This is code:
import time
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://temp-mail.org/")
time.sleep(10)
browser.close()
The link opens correctly but I can't pass cloudflare.
Also, I see some errors on my console:
Thanks...
Try adding user agent argument in chrome options and set user agent to any value
ops = Options()
ua='me'
ops.add_argument('--user-agent=%s' % ua)
driver=uc.Chrome(executable_path=r"C:\chromedriver.exe",chrome_options=ops)
Alternatively try using undetected-chromedriver
import undetected_chromedriver as uc
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = uc.Chrome(options=options)
driver.get("https://temp-mail.org/")

Hi, I am having problems with getting through to a site using DDos protection by cloudflare, when using python and selenium

I am planning to set up an automated prosess on a website. But cant get through the message 'Checking your browser before accessing sit.no' when I try to reach the site using selenium. The message is from cloudflare.
I have been trying some code that i found here but it didnt work
1.
from selenium import webdriver
url = 'https://www.sit.no/'
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options)
driver.get(url)
2.
from selenium import webdriver
url = 'https://www.sit.no/'
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options)
driver.get(url)
3.
import undetected_chromedriver as uc
url = 'https://www.sit.no/'
driver= uc.Chrome()
driver.get(url)
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import subprocess
#other imports
subprocess.Popen(
'"C:\\Program Files\\yourpathtochrome\\chrome.exe" --remote-debugging-port=9222', shell=True)
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.get('https://www.sit.no/')
input()
first open the website manually and complete the browser check. now Close all chrome browsers and replace the path with your chrome.exe path. This will work ,

Python Selenium Clear Chrome Cookies

I'm trying to clear my chrome cookies, but i can't click a button: BUTTON
import os
import time
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
opt = Options()
opt.add_argument("start-maximized")
executable_path = r'chromedriver'
os.environ["webdriver.chrome.driver"] = executable_path
global driver
driver = webdriver.Chrome(r'C:\Users\SAMSUNG\Desktop\chromedriver', options=opt)
driver.get("https://www.youtube.com")
driver.get("chrome://settings/clearBrowserData")
time.sleep(2)
driver.find_element_by_css_selector('#clearBrowsingDataConfirm').click()
The problem comes form the chained shadowroots that doesn't allow for the element to be found:
driver.get("https://www.youtube.com")
driver.get("chrome://settings/clearBrowserData")
time.sleep(5)
javaScript = "document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-section > settings-privacy-page').shadowRoot.querySelector('settings-clear-browsing-data-dialog').shadowRoot.querySelector('#clearBrowsingDataDialog').querySelector('#clearBrowsingDataConfirm').click()"
driver.execute_script(javaScript)

Categories

Resources