Python Selenium Recaphta I am not a robot - how to bypass - python

First of all, I am not by any means an expert scraping the web, selenium, or have a good understanding of html...
I am trying to download a CSV file that is hidden behind a 'recaptcha - i am not a robot'. I first must login to the website and then there is link that generates the I am not a robot captcha. It is the kind that you just click a box and must hit 'yes, i am not a robot' button.
I can't figure out how to get this to work. I've seen things about finding the x/y coordinates of where the box pops up and clicking, but I can't seem to figure that out. There seems potentially other methods, but I'm just having a hard time deciphering what to do and then how to do. My code thus far...
import selenium
browser = webdriver.Chrome()
browser.get("mywebsite")
username = browser.find_element_by_id("Email")
password = browser.find_element_by_id("Password")
username.send_keys('<<MY_EMAIL_FOR_LOGIN>>')
password.send_keys('<<MY_PASSWORD_FOR_LOGIN>>')
browser.find_element_by_xpath('//*[#id="container"]/div[3]/div[1]/div[1]/form/div[2]/div[2]/div[1]/input[6]').click() #button to 'login'
# so far so good - I am logged in!
elements = browser.find_element_by_id("patient-export-button")
elements
browser.execute_script("arguments[0].click();", elements)
# the lines above will cause the recaptcha popup to appear.
# now I am STUCK!
I have to now click the checkbox & hit 'yes' in order for my file to download. Sometimes when I hit the checkbox I get all these stupid 'find the car' images which are a pain in the ass for me to solve even as a human...
Any help on solving this recaptcha thing would be appreciated.

Related

Basic runtime script error on python with selenium

I would like to point out that I am a beginner and that I started barely 48 hours ago.
I want to code a script that runs a page, enters username and password, click in the login button and clicks in a tab once logged in.
But I encounter an error, it only opens the page for me and does not enter any id/pw and click.
I tried to search and try some changes in the path but it doesn't change anything, and at worst doesn't launch my page anymore, I'm a little lost so I ask for your help please.
enter image description here
From the Selenium docs Finding Web Elements
So in your code,
import By from selenium.webdriver.common.by import By
and use wb.find_element(By.XPATH,"your_xpath")

Use Selenium to get facebook "seemore" button

I want to scrape the content of the top ten posts on my fan page, but the content is hidden and I need to press "seemore", but I can't find the corresponding location with Selenium.
This problem has been bothering me for a long time, hope someone can help
PS: Non-native English speakers, please forgive me if the useful words are inappropriate
driver.find_element(By.XPATH, '//\*\[#id="jsc_c_1m"\]/div/div/span/div\[2\]/div\[3\]/div').click()
button = driver.find_element(By.XPATH, '//\*\[#id="jsc_c_y4"\]/div/div/span/div\[2\]/div\[3\]/div')
driver.excute_script("arguments\[0\].click();",button)
driver.find_element(By.PARTIAL_LINK_TEXT,'seemore').click()

How to click on an element with Selenium without using Driver.get?

So I am trying to write a code to automatically join a google meet. So I need to sign into my google account, which runs all fine but when I get to "Verify that it's you" (image 1), and I try to use driver.get it takes me back to the original sign-in page (image 2)
How can I click on the "Continue" button without using driver.get/without getting taken back to the original sign-in page. I know that all I have to do is click on the "Continue" because when I do it manually it works perfectly. Pressing "Tab" and then "Enter" would also work, but it seems you need to use driver.get as well. Thank you
so i think you don't understand driver.get() usage. it is used only to make the browser browse to a specific link which you can specify before hand. what you have to do here is open the google meet page manually and go to your required page where you want to click the button. right click on the button and click on inspect. then go to the higlighted code and locate the button you want and right click on copy and select xpath from the list. now coming to your code.
add this line:
element=driver.find_element_by_xpath('_xpath')
element.click()
replace _xpath with the long string you copied (which is the xpath of the button you want to click).
this is the way to click on buttons or text boxes or anything you name it in selenium.
**beware of one thing. don't make your code click immediately. if the page does not fully load and the click is made then the 1st line will throw an element not found error. put some kind of delay till page loads or use a while loop and exception handling to wait till the element is found
This one should work for you
userName = driver.find_element_by_xpath("//button[#name='username']")
driver.execute_script("arguments[0].click();", userName)

Selenium Instagram Bot - Clicking the "Like" Button

I have written a program to go on the Instagram explore page, and like the first six photos.
Right now, I am using this rather convoluted method to find the "Like" button.
I would much rather have it formatted like I did the "click the login button" section.
So far, I have tried inspecting various elements, but I cannot pinpoint the correct one to make it uniquely select the "Like" button. Also, I could just need to use an attribute that I am unfamiliar with to uniquely select the like button.
I am super new to the python and also the selenium, so any help is appreciated.
#like
self.driver.find_element_by_xpath('//*[#id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button').click()
sleep(3)
#Click login button
self.driver.find_element_by_xpath('//button[#type = "submit"]').click()
sleep(3)
to click on like, that web element is in svg tag, so try the below locator :
//button[#type='button']//*[name()='svg' and #aria-label='Like' and #height='24']
something like :
sleep(3)
self.driver.find_element_by_xpath("//button[#type='button']//*[name()='svg' and #aria-label='Like' and #height='24']").click()
Also, I am not sure what do you mean by
#Click login button

Python Selenium Webdriver - Handling mouseover on Instagram

I'm creating an Instagram Unfollow Tool. The code usually works, but occasionally Instagram will show the information of some user (as if I hovered over that user) and cause my code to stop running because it obscures the buttons that I need to click in order to unfollow a user.
It's easier to understand with an example:
How can I edit my code to make the mouseover information go away (is there a way to turn off these mouseover effects)?
My code:
for i in range(num_following):
following = self.browser.find_element_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[{}]/div/div[1]/div[2]/div[1]/span/a".format(i))
following_username = following.get_attribute("title")
if following_username not in followers:
# Unfollow account
following_user_button = self.browser.find_element_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[{}]/div/div[2]/button".format(i))
following_user_button.click()
unfollow_user_button = self.browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div[3]/button[1]")
unfollow_user_button.click()
print("You've unfollowed {}.".format(following_username))
The error I get:
selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (781,461) because another element obscures it
It seems like the element unfollow_user_button = self.browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div[3]/button[1]") you want to execute .click() on is blocked by a temporary or permanent overlay.
In such cases you either can wait with ExplicitWait and ExplicitConditions till said blocking element has vanished - though this shouldn't work in this specific case as to my knowledge the popup remains if nothing is done. Another approach is to send the click directly to the element by using the JavascriptExecutor:
#Find the element - by_xpath or alike
unfollow_user_button = driver.find_element_by_xpath("XPATH")
#Sending the click via JavascriptExecutor
driver.execute_script("arguments[0].click();", unfollow_user_button)
Note two things:
driver must obviously be an instance of WebDriver.
I would suggest not using the absolute XPath in general. Going with the relative XPath is less prone to be broken by small changes in the site structure. Click here for a small guide to read through.

Categories

Resources