I am using a captcha bypass extension called "Buster: Captcha Solver for Humans
1.3.1". Works great but cant seem to click on its button for this website because its blocked by a shadowroot. I have no experience in bypassing shadowroots so please any help would be GREATLY appreciated. I have been working for this on hours and still have no luck. Below is a snippet of the code I am making for this site. The site is https://www.biblegateway.com/newsletters/ and the captcha in the shadow root appears when you enter a email and click on subscribe. I posted pics to help describe this problem as well!
from lib2to3.pgen2 import driver
import random
import string
import selenium
from selenium import webdriver
from selenium.webdriver.chrome import options
from selenium.webdriver.common.keys import Keys
import time
from time import sleep, time_ns
import pynput
import threading
from threading import Thread
from pynput.keyboard import Key, Controller
from selenium.webdriver.chrome.options import Options
PATH = "C:\Program Files (x86)\chromedriver.exe"
chrome_options1 = Options()
chrome_options1.add_extension(r'D:\mpbjkejclgfgadiemmefgebjfooflfhl.crx')
driver1 = webdriver.Chrome(executable_path= PATH, options=chrome_options1)
driver1.get("https://www.biblegateway.com/newsletters/")
driver1.maximize_window()
email_box = driver1.find_element_by_xpath('/html/body/div[2]/div/section/div[3]/section/form/div/div/div[2]/div[2]/div[1]/input')
email_box.click()
email_box.send_keys('testingthecaptcha#gmail.com')
time.sleep(2)
clicky = driver1.find_element_by_xpath('/html/body/div[2]/div/section/div[3]/section/form/div/div/div[1]/div[1]/div[2]/label[1]/input')
clicky.click()
time.sleep(3)
clicky1 = driver1.find_element_by_xpath('/html/body/div[2]/div/section/div[3]/section/form/div/div/div[2]/div[2]/div[2]/input')
clicky1.click()
print('done')
time.sleep(2)
#Below is where I just could not click the element or bypass the shadowroot!!!!!!!
captcha_solver = driver1.find_element_by_xpath("//input[#placeholder='Instrument']")
captcha_solver.click()
time.sleep(3)
print('done')
Using selenium 4:
shadow_root = driver.find_element(By.XPATH, 'shadow-root-parent-element').shadow_root
element_in_shadow_root = shadow_root.find_element(By.XPATH, 'element-in-shadow-root')
e.g.
shadow_root = driver.find_element(By.CSS_SELECTOR, 'game-app').shadow_root
game = shadow_root.find_element(By.CSS_SELECTOR, '#game')
Related
`
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from time import sleep
import os
login_page = "https://fap.fpt.edu.vn/Default.aspx"
# page = "https://fap.fpt.edu.vn/Report/ScheduleOfWeek.aspx"
email = ""
password = ""
options = Options()
options.add_argument("--window-size=1920,1080")
options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"
driver = webdriver.Chrome(options = options)
driver.get(login_page)
login1 = driver.find_element("xpath","//div[#class='abcRioButtonContentWrapper']").click()
driver.find_element(By.NAME, "identifier").send_keys(email)
sleep(3)
driver.find_element(By.ID, "identifierNext").click()
sleep(2)
driver.find_element(By.NAME, "password").send_keys(password)
sleep(2)
driver.find_element(By.ID, "passwordNext").click()
sleep(999999)
`
I believe i chose the right By.NAME ( "indentifier" ) but the code still not work and return message no such element.
I tried to change the syntax, using xpath change By.NAME to By.ID but it still not work
Google login page opens in a new window. So you need to switch to this window before interacting with it. So you need to use this code (the first and the last lines are from your code and between is the part you need to add):
login1 = driver.find_element("xpath","//div[#class='abcRioButtonContentWrapper']").click()
windows = driver.window_handles
driver.switch_to.window(windows[1])
driver.find_element(By.NAME, "identifier").send_keys(email)
And after you've finished with the login you will need to switch back to the main window. To do that you can use this code:
driver.switch_to.window(windows[0])
And then work with the content of the page
No, don't use name of jsname here, because they get filled with random data.
Just find your Google account name or your email address by text and click it:
userAccount = driver.find_element_by_xpath("//*[text()='YourGoogleAccountName']")
userAccount.click()
I am working on a auto form submitting project I tried selenium but I could fill the forms but when I click submit button a recaptcha being summoned, when I tried to bypass it with 2captcha but didn't work and after that I tried to do it manually but when I do it correctly it gets reseted can you help me with my code?
import time
import os
import requests
import random
import string
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver as wd
import sys
def random_char(y):
return ''.join(random.choice(string.ascii_letters) for x in range(y))
mail = (random_char(7)+"#gmail.com")
driver = wd.Firefox(executable_path='C:\geckodriver.exe')
target_url = 'https://www.yemeksepeti.com/login/new?step=registration'
driver.get(target_url)
driver.maximize_window()
time.sleep(2)
print(mail)
time.sleep(2)
email = str(mail)
time.sleep(2)
firstName = 'Mert'
time.sleep(2)
lastName = 'Demir'
time.sleep(2)
birthDate = '01-04-2001'
time.sleep(2)
password = 'AbcAbc123.*_123'
time.sleep(2)
emailPath = driver.find_element("xpath", '//*[#id="email"]')
time.sleep(2)
emailPath.send_keys(mail)
time.sleep(2)
firstNamePath = driver.find_element("xpath", '//*[#id="first_name"]')
time.sleep(2)
firstNamePath.send_keys(firstName)
time.sleep(2)
lastNamePath = driver.find_element("xpath", '//*[#id="last_name"]')
time.sleep(2)
lastNamePath.send_keys(lastName)
time.sleep(2)
birthDatePath = driver.find_element("xpath", '//*[#id="birthdate"]')
time.sleep(2)
birthDatePath.send_keys(birthDate)
time.sleep(2)
passwordPath = driver.find_element("xpath", '//*[#id="password"]')
time.sleep(2)
passwordPath.send_keys(password)
time.sleep(2)
Submit = driver.find_element("xpath", '//*[#id="login-page-react-root"]/main/div/form/div[8]/button')
Submit.click()
time.sleep(2)
The main reason for having a re-captcha is to stop bots (ie: selenium automation scripts) from interacting with the web page/form.
If you can bypass that this is a big red light for the application security. And is not recommended in standard QA practices.
What you need to do is to have your dev environment configured to be test friendly. There are multiple ways this can be achieved. From my personal experience :
Remove the captcha field for dev/test environment forms.
Have the developers setup a static captcha which always has one known captcha phrase
Test the feature with the captcha manually
I'm sure there are a lot of other ways to overcome this situation, but forcing the script to enter the real captcha is not the way to go
I need to move an user with selenium to a list, I tried with drag and drop command but I cant do it, the only way that the platform lets me move a user to the list is by drag and drop it to list so
any help?
import email
from importlib.resources import path
from lib2to3.pgen2 import driver
import webbrowser
import unittest
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
path="C:\\Users\\ysarmiento\\Desktop\\PythonVsCode\\chromedriver.exe"
username="obviusly not gonna show"
password="same"
path="C:\\Users\\ysarmiento\\Desktop\\PythonVsCode\\chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get("https://beanalyzer.teldat.com/login")
driver.maximize_window()
driver.find_element_by_id("email").send_keys(username)
driver.find_element_by_id("password").send_keys(password)
driver.find_element_by_xpath("/html/body/div/div[2]/div[1]/form/button").click()
sleep(3)
driver.get("https://beanalyzer.teldat.com/settings/system-provisioning")
target=driver.find_element_by_xpath('//*[#id="main-el"]/div[3]/div/div[2]')
value=driver.find_element_by_xpath('//*[#id="peculiar"]/div/div/div[1]')
actions=ActionChains(driver)
actions.drag_and_drop(target,value).perform()
sleep(4)
I have this and it doesn't give me any errors but it doesn't work, for locating the elements I'm using Xpath (cause some users and lists doesn't have an id or name)
I'm putting here the type of list and user(element) if needed
User Element
type of list
if you need something else let me know
thank you for your time
I'm pretty new in programming so I might be an easy question, but I don't understand why the browsers opened by Selenium closes at the end of the code.
from lib2to3.pgen2 import driver
from selenium import webdriver
def Online_PLatform():
Driver = webdriver.Chrome()
Driver.get('https://elearningmarikina.ph/')
Gmail = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[1]/input')
Gmail.send_keys('958rectin#depedmarikina.com')
Pass = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[2]/input')
Pass.send_keys('33112')
Button = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[3]/button')
Button.click()
You can use 2 approaches in order to keep you driver open.
1.
Add the 'detach' option to your driver settings:
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
Simply add a delay at the end of your test code (less elegant approach but more simple)
from lib2to3.pgen2 import driver
from selenium import webdriver
import time
def Online_PLatform():
Driver = webdriver.Chrome()
Driver.get('https://elearningmarikina.ph/')
Gmail = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[1]/input')
Gmail.send_keys('958rectin#depedmarikina.com')
Pass = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[2]/input')
Pass.send_keys('33112')
Button = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[3]/button')
Button.click()
time.sleep(50)
This is because after the all functions, The code stops running and that's why selenium exits.
You can use the time module to delay.
import time
from lib2to3.pgen2 import driver
from selenium import webdriver
def Online_PLatform():
Driver = webdriver.Chrome()
Driver.get('https://elearningmarikina.ph/')
Gmail = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[1]/input')
Gmail.send_keys('958rectin#depedmarikina.com')
Pass = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[2]/input')
Pass.send_keys('33112')
Button = Driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[2]/div/div/form/div[3]/button')
Button.click()
time.sleep(50) #---> 50 second delay
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
import schedule
browser = webdriver.Chrome('/Users/badernm/Desktop/chromedriver')
browser.get('https://www.instagram.com/accounts/password/reset/')
usrname_bar = browser.find_element_by_name('cppEmailOrUsername')
username = '17pii_'
usrname_bar.send_keys(username + Keys.ENTER
i need to print the result that is ("thanks! check your email for reset link ")
or ("no account with this email")
I re-created your program and added 4 extra lines that grab that text from the pop-up you want. Then it prints the text to your terminal. I also took out the 'schedule' library because I saw that you weren't using it in your code, but you can add it back in if you're just showing us a snippet of your program.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
browser = webdriver.Chrome('/Users/badernm/Desktop/chromedriver')
browser.get('https://www.instagram.com/accounts/password/reset/')
usrname_bar = browser.find_element_by_name('cppEmailOrUsername')
username = '17pii_'
usrname_bar.send_keys(username + Keys.ENTER)
time.sleep(1) # Wait for pop-up message
result = browser.find_element_by_xpath("html/body/div/div/div/div/p") # Path to pop-up
print(result.text) # Get pop-up text
browser.quit() # Quit browser process
You can get the element by class name. It will look something like this:
reply = browser.find_element_by_class_name("CgFia")
print(reply.text)