very simple selenium auto-click for webpage does not work - selenium

I am very new.
I was trying to make an auto mail sender for practice.
It opens website but not the login button.
There is nothing happen after it opened.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(
executable_path='/Users/aidencho/practice/chromedriver', options = options)
# open a website
url = 'https://naver.com'
driver.get(url)
# driver.maximize_window()
action = ActionChains(driver)
driver.find_element_by_css_selector('.link_login').click()
# driver.find_element_by_css_selector("#account > a").click()
# driver.find_element_by_class_name('.account > a').click()
One more thing.
I saw someone doing this, and there was a completed sentence for driver.find_element_by_css_selector part even he typed only driver.find.
Why not me?
Would there be a setting problem?
enter image description here

find_element_by_css_selector is deprecated. Please use find_element(by=By.CSS_SELECTOR, value=css_selector) instead.
driver.find_element(by="css selector", value='.link_login')

Related

ElementNotInteractableException: Message: Element<input id="email" class="input-text" name="login[username]" type="email">is not reachable by keyboard

I have a problem trying to enter my username and password with Selenium WebDriver using Firefox on Windows, for some reason it does not allow me to enter the email and password, I have tried using elements such as: ID, CSS, Class... but it shows me the error message:
ElementNotInteractableException: Message: Element is not reachable by keyboard
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
# Driver Configuration
browser = webdriver.Firefox(executable_path=r'C:\geckodriver.exe')
browser.get('https://b2b.bluewaycorp.com/index.php/customer/account/login/')
time.sleep(4)
# Input User
username_el = browser.find_element_by_id("email")
username_el.send_keys('user_mail#gmail.es') # ERROR WHEN I TRY TO INPUT TEXT!!
time.sleep(0.5)
# Input Password
password_el = browser.find_element_by_id("pass")
password_el.send_keys("password") # ERROR WHEN I TRY TO INPUT TEXT!!
time.sleep(0.5)
submit_btn_el2 = browser.find_element_by_xpath("/html/body/div[1]/main/div[3]/div/div[2]/div[1]/div[2]/form/fieldset/div[4]/div[1]/button/span")
time.sleep(1)
submit_btn_el2.click()
I would like to know what elements of the code I am missing to be able to enter the user and the mail, it is probable that first I will have to interact with the class both elements or use other functions from selenium
There are more than one elements with the same property, that's why your code is not working:
for Email field, use this:
browser.find_elelment(By.XPATH, "(//input[#name='login[username]'])[3]").send_keys('user_mail#gmail.es')
for Password field, use this:
browser.find_elelment(By.XPATH, "(//input[#name='login[password]'])[3]").send_keys('password')

Login to Tiktok using Selenium?

i'm currently to use the script below to upload tiktok videos, however when running the script im getting hit with the error message "Too many attempts. Try again later." regardless of what login method i use, rotating headers don't seem to fix the error. Any advice?
import time
import random
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from webdriver_manager.chrome import ChromeDriverManager as CM
import undetected_chromedriver.v2 as uc
import undetected_chromedriver as uc
print('=====================================================================================================')
print('Heyy, you have to login manully on tiktok, so the bot will wait you 1 minute for loging in manually!')
print('=====================================================================================================')
time.sleep(8)
print('Running bot now, get ready and login manually...')
time.sleep(4)
bot = uc.Chrome()
options = webdriver.ChromeOptions()
option.add_argument("--profile-directory=Default")
bot = webdriver.Chrome(options=options, executable_path=CM().install())
bot.set_window_size(1680, 900)
bot.get('https://www.tiktok.com/login')
ActionChains(bot).key_down(Keys.CONTROL).send_keys(
'-').key_up(Keys.CONTROL).perform()
ActionChains(bot).key_down(Keys.CONTROL).send_keys(
'-').key_up(Keys.CONTROL).perform()
print('Waiting 50s for manual login...')
time.sleep(50)
bot.get('https://www.tiktok.com/upload/?lang=en')
time.sleep(3)
def check_exists_by_xpath(driver, xpath):
try:
driver.find_element_by_xpath(xpath)
except NoSuchElementException:
return False
return True
def upload(video_path):
while True:
file_uploader = bot.find_element_by_xpath(
'//*[#id="main"]/div[2]/div/div[2]/div[2]/div/div/input')
file_uploader.send_keys(video_path)
caption = bot.find_element_by_xpath(
'//*[#id="main"]/div[2]/div/div[2]/div[3]/div[1]/div[1]/div[2]/div/div[1]/div/div/div/div/div/div/span')
bot.implicitly_wait(10)
ActionChains(bot).move_to_element(caption).click(
caption).perform()
# ActionChains(bot).key_down(Keys.CONTROL).send_keys(
# 'v').key_up(Keys.CONTROL).perform()
with open(r"caption.txt", "r") as f:
tags = [line.strip() for line in f]
for tag in tags:
ActionChains(bot).send_keys(tag).perform()
time.sleep(2)
ActionChains(bot).send_keys(Keys.RETURN).perform()
time.sleep(1)
time.sleep(5)
bot.execute_script("window.scrollTo(150, 300);")
time.sleep(5)
post = WebDriverWait(bot, 100).until(
EC.visibility_of_element_located(
(By.XPATH, '//*[#id="main"]/div[2]/div/div[2]/div[3]/div[5]/button[2]')))
post.click()
time.sleep(30)
if check_exists_by_xpath(bot, '//*[#id="portal-container"]/div/div/div[1]/div[2]'):
reupload = WebDriverWait(bot, 100).until(EC.visibility_of_element_located(
(By.XPATH, '//*[#id="portal-container"]/div/div/div[1]/div[2]')))
reupload.click()
else:
print('Unknown error cooldown')
while True:
time.sleep(600)
post.click()
time.sleep(15)
if check_exists_by_xpath(bot, '//*[#id="portal-container"]/div/div/div[1]/div[2]'):
break
if check_exists_by_xpath(bot, '//*[#id="portal-container"]/div/div/div[1]/div[2]'):
reupload = WebDriverWait(bot, 100).until(EC.visibility_of_element_located(
(By.XPATH, '//*[#id="portal-container"]/div/div/div[1]/div[2]')))
reupload.click()
time.sleep(1)
# ================================================================
# Here is the path of the video that you want to upload in tiktok.
# Plese edit the path because this is different to everyone.
upload(r"C:\Users\redi\Videos\your-video-here.mov")
# ================================================================
Anyone have a workaround the Tiktok block?
While attempting to login, re-login or creating an account TikTok platform may even wrongly identify you as a bot or spam and for the next 5 minutes or so, you may keep getting the Too many attempts. Try again later. error message when trying to sign in to TikTok as follows.
To avoid getting detected as a bot you can use your default user login profile and you can use the following solution:
options = Options()
options.add_argument("start-maximized")
# Chrome is controlled by automated test software
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
# avoiding detection
options.add_argument('--disable-blink-features=AutomationControlled')
# Default User Profile
options.add_argument("--profile-directory=Default")
options.add_argument("--user-data-dir=C:/Users/Admin/AppData/Local/Google/Chrome/User Data")
bot = webdriver.Chrome(options=options, executable_path=CM().install())
bot.get('https://www.tiktok.com/login')

Trouble clicking on a next-page button with webscraping (Selenium)

I'm trying to webscrape this page https://www.bumeran.com.pe/empleos-publicacion-menor-a-7-dias.html. However, I'm having trouble clicking on the next-page button to scrape all the pages. I've tried doing this:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
PATH = "C:\Program Files (x86)\chromedriver.exe"
wd = webdriver.Chrome(PATH, options=options)
wd.maximize_window()
wd.get("https://www.bumeran.com.pe/empleos-publicacion-menor-a-7-dias.html")
def pag_sig():
element_present = EC.visibility_of_element_located((By.XPATH, '//*[#class="Pagination__NextPage-sc-el3mid-4 gSlsBf"]/i'))
boton = WebDriverWait(wd,5).until(element_present)
boton.click()
page_max=127 #I get this with another piece of code
for i in range(page_max):
pag_sig()
However, this does not work properly. Sometimes my scraper clicks on other links rather than the button itself. I've tried adding waits but it doesn't work. How could I approach this problem?
May its because of not scrolling down. Try the below xpath and code once.
#xpath - //div[#id='listado-avisos']//button[#class='Pagination__NextPage-sc-el3mid-4 gSlsBf']
driver.get("https://www.bumeran.com.pe/empleos-publicacion-menor-a-7-dias.html")
for i in range (5):
nextoption = driver.find_element_by_xpath("//div[#id='listado-avisos']//button[#class='Pagination__NextPage-sc-el3mid-4 gSlsBf']")
driver.execute_script("arguments[0].scrollIntoView(true);", nextoption)
driver.execute_script("window.scrollBy(0,-300)")
nextoption.click()
time.sleep(3)
You can click on the button instead of directly clicking on the i below can help, I hope
button = WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//button[#class='Pagination__NextPage-sc-el3mid-4 gSlsBf']")))
button.click()

Unable to log in using selenium

I am trying to scrape this website using python's BeautifulSoup package and for automating the user flow I am using selenium. As this website requires authentication to access this page, I am trying to log in first using selenium webdriver. Here is my code:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
def configure_driver():
# Add additional Options to the webdriver
chrome_options = Options()
# add the argument and make the browser Headless.
chrome_options.add_argument("--headless")
# Instantiate the Webdriver: Mention the executable path of the webdriver you have downloaded
# For linux/Mac
# driver = webdriver.Chrome(options = chrome_options)
# For windows
driver = webdriver.Chrome(executable_path="/home/<user_name>/Downloads/chromedriver_linux64/chromedriver",
options = chrome_options)
return driver
def getLinks(driver):
# Step 1: Go to pluralsight.com, category section with selected search keyword
driver.get(f"https://www.coursera.org/learn/competitive-data-science/supplement/RrrDR/additional-material-and-links")
# wait for the element to load
try:
WebDriverWait(driver, 5).until(lambda s: s.find_element_by_class_name("_ojjigd").is_displayed())
except TimeoutException:
print("TimeoutException: Element not found")
return None
email = driver.find_element_by_name('email')
print(str(email))
password = driver.find_element_by_name('password')
email.send_keys("username") # provide some actual username
password.send_keys("password") # provide some actual password
form = driver.find_element_by_name('login')
print(form.submit())
WebDriverWait(driver, 10)
print(driver.title)
soup = BeautifulSoup(driver.page_source)
# Step 3: Iterate over the search result and fetch the course
divs = soup.findAll('div', args={'class': 'item-box-content'})
print(len(divs))
# create the driver object.
driver = configure_driver()
getLinks(driver)
# close the driver.
driver.close()
Now after doing form.submit() it is expected to log in and change the page, right? But it is simply staying in the same page, so I cannot access the contents of the authenticated page. Someone please help.
That is because there is no name attribute.
instead of this :
form = driver.find_element_by_name('login')
Use this :
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Login']"))).click()
I tried this code on my local, seems to be working fine
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("https://www.coursera.org/learn/competitive-data-science/supplement/RrrDR/additional-material-and-links")
wait.until(EC.element_to_be_clickable((By.ID, "email"))).send_keys("some user name")
wait.until(EC.element_to_be_clickable((By.ID, "password"))).send_keys("some user name")
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Login']"))).click()
Since login button is in a form so .submit() should work too.
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Login']"))).submit()
This works too.

How to disable navigator.webdriver using Selenium in VBA? [duplicate]

Been searching for a while and tried all the solutions present but none appear to be working. I created a "slide show" that will first log in, then alternate between tabs. All of that is working but i cannot get rid of the
"Chrome is being controlled by automated test software" bar. Any advise?
Code
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
usernameStr = 'test'
passwordStr = 'test'
browser = webdriver.Chrome()
#first tab
browser.get(('www.testwebsite.com?'))
# fill in username and hit the next button
username = browser.find_element_by_id('username')
username.send_keys(usernameStr)
password = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, 'password')))
password.send_keys(passwordStr)
nextButton = browser.find_element_by_class_name('emp-submit')
nextButton.click()
#second tab
browser.execute_script("window.open('about:blank', 'tab2');")
browser.switch_to.window("tab2")
browser.get('www.testwebsite.com')
Try this:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("excludeSwitches",["enable-automation"])
driver_path = '/Users/myuser/Downloads/chromedriver'
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
driver.get('https://google.com')
driver.close()
When you open Chrome Browser in through ChromeDriver this infobar containing the notification is embedded as follows:
Chrome is being controlled by automated test software
Browser snapshot without the argument disable-infobars:
But if you add the argument disable-infobars through an instance of ChromeOptions you can get rid of this infobar as follows:
Code Block:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.google.com/')
Browser snapshot applying the argument disable-infobars:
THIS IS WORKING WITH LATEST RELEASE.
Try it by changing driver path under "service_obj"
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches",["enable-automation"])
service_obj = Service(r"C:\Users\Documents\Sublime_srk\drivers\chromedriver_win32\chromedriver.exe")
driver = webdriver.Chrome(options=chrome_options,service=service_obj)
driver.get("https://www.google.co.in/")
Click on the "x" to close the bar. It doesn't work initially, but then maximize and restore the window and it should disappear. This is for anyone who doesn't trigger their tests through Java.