How to detect CAPTCHA and solve it manually using selenium and python? - python

I'm working on simple program based on python and selenium.
The program fills all fields with some personal information and sends the information with "confirm" button.
Once the button is pressed, a CAPTCHA must be solved, is there a way to detect the captcha, solve it manually and then send the answer?
The program is in headless mode and I read that it is impossible to disable this mode when code is running...I was thinking to find the CAPTCHA as a "link" and open it on a second page maybe.
Is there any way to do this?

Related

How to talk with alert from page and not browser with Selenium

This is what the alert looks like. It reads: The proxy it3.prmsrvs.com is requesting a username and password I have a program in Selenium that automates a certain amount of stuff on a website.
For some reason (this has been encountered also by my colleagues when using the browser normally without automation) there is the possibility of a pop-up showing in the webpage at a random point.
My program's objective is to load a page, get a list of all the elements corresponding to a specific tag and then click on them one by one. They all open in a new tab.
There is the possibility of a pop-up to show in the page after closing one of the tabs.
This pop-up asks for a login but all I have to do is dismiss it and the page will keep working like always.
Now, I've seen people using driver.switch_to.alert.dismiss() but this doesn't seem to work on this page.
I checked the function on a very basic js alert and the dismiss works perfectly, so I think it's the type of alert that is the issue.
I can't inspect the page so I don't know how to retrieve the iFrame of this alert. (I saw this as a possible solution online)
What should I do?

How can I click "invisible" reCAPTCHA buttons using Selenium web automation?

I am using Python and Selenium to automate this website: https://prenotami.esteri.it
The script I made fills out a form and then clicks a button to advance to the next page. These actions are carried out using Selenium's find_element_by_xpath() function. Recently, the website added a reCAPTCHA that pops up after the button is clicked, and must be completed before advancing.
I have already written a Python script that is capable of surpassing this type of captchas by using the audio option. However, in this particular website, I am not able to find the xpath to the audio button of the reCAPTCHA. Although there is an iframe that contains the reCAPTCHA, there seems not to be anything inside it.
In the first attached image you can see how this website's reCAPTCHA looks like in HTML, compared to other website that is visible in the second image, where a #document can be seen inside the iframe.
My intention is to run this program using headless Chrome, so I can't relay in any mouse control functions offered by pyautogui for example.
I've been scratching my head around this problem for a while, so any advice is useful. Thanks!
Edit: after some research I have found that this type of reCAPTCHA that doesn't need to check a "I am not a robot" checkbox is called "invisible reCAPTCHA". The captcha only pops up if the detected activity is suspicious (for example clicking too fast). I have tried adding random waits and movements to mimic human behaviour, but the captcha still appears after some tries. Since I don't think there is a way to avoid the captcha from appearing 100% of the times, the question of how to click the buttons using Selenium's find_element_by_xpath() function remains the same. Leaving this as a note just in case someone finds it useful.
Ever tried to use the following function:
add_argument("-auto-open-devtools-for-tabs")
I managed to interact with captcha
If the position is always fixed, you can use PyAutoGUI to move the mouse and click on it
import pyautogui
pyautogui.click(100, 100) # button coordinates
Since, it is in iframe, we need to move our selenium pointing to iframe and then use your xpath.
driver.switch_to.frame("c-la7g7xqfbit4")
capchaBtn = driver.find_element_by_xpath("(//button[#id='recaptcha-audio-button'])[2]")

Is it possible to pick a specific button, that is on a page multiple times with selenium?

I am trying to code a program for somebody, that is possible to send and delete messages at the same time in the browser Discord application.(I think he wants to use this to spam?) He told me to write the code in Python, so I used python with Selenium. At this point I got everything working so far, the login works, the channel select works if you just insert the channel link directly. It also managed to let it send some messages. But problem now is, that I don't know how to delete the message after it was send, beacuse you need to click a "More" button first. But this more Button
I would use Webbot for that:
from webbot import Browser
web = Browser()
web.click('More')
that module has quite a few useful simple functions so i encourage you to try it

Is there a way to get HTML data from an active browser (Python)

I'm just messing around with python automation and attempting to create a Cookie Clicker bot.
I was wondering if you can get HTML data (e.g ID's Names, etc) from an already open browser,
and use them into locating where to click, if you should click, etc. Don't know if it's a dumb question, but I'm a beginner so help would be appreciated.
*I have tried selenium, but the point is to be able to control my main chrome browser
I'd check out stuff like Selenium and robotic process automation for that. Try this: https://realpython.com/modern-web-automation-with-python-and-selenium/

Sometimes not sending full text to input as expected by sendkeys in selenium python

I try to login a site automatically by selenium.
My script sometimes works smoothly but sometimes it does not send full-text of user name or passwork to relavant inputs so it then failed to login.
I try to insert implicitly_wait but it appears not to solve this problem totally.
I wonder if there is any function to require the webdriver to fullfill each of input before excecute another one in selenium.
Here is may attempt:
browserdriver.get(url)
#fill username
browserdriver.implicitly_wait(25)
psusername=browserdriver.find_element_by_xpath("//*[#class='form-group'][1]/input[#name='username']")
psusername.click()
psusername.send_keys("1234567890")
#fill password
browserdriver.implicitly_wait(25)
pspass=browserdriver.find_element_by_xpath("//*[#class='form-group'][2]/input[#name='password']")
pspass.click()
pspass.send_keys("abcdefgfk12345")
browserdriver.implicitly_wait(25)
pssubmit=browserdriver.find_element_by_xpath("//*[#class='login-btn']/button[#type='submit']")
pssubmit.click()
Pls, explain for me why I get stuck on this problem and how to solve it! thanks alot
EDIT1: I add the target site address: click here You should click on login words (Đăng nhập) on the top right screen to see the popup login pannel.
EDIT 2: Thank to guide of below comments, I try to add some code lines to force it to key individual letter and it appears to work well so I add solution here:
text_input="1234567890"
for i in text_input:
psusername.send_keys(i)
Use set attribute instead of sendkeys
here is the example code:
webdriver.executeScript("document.getElementById('elementID').setAttribute('value', '1234567890')");

Categories