Python selenium a button can't be clicked - python

I am new for python selenium. I have been working for a script and I cannot press save gift options button. I used every ways(xpath css) but I couldn't. what should I do to press this button?
Snapshot of the button:

sometime x-path does not work. In my case every time buttons does not work when i find using x-path. You have to find button with it's ID and then apply click function.

Related

How to fetch text from the canvas loaded with game?

I am facing the situation where I have to automate certain stuff, the exact scenario is I have the game loaded in the canvas, and I can able to do the click actions inside the canvas(using Actionchains offset by selenium in python) but on click, there are certain actions happening on the game like it will display some values on button click and the values get changed on every click action of the button, Here I need to fetch those text(values).
By using selenium and python, I can able to achieve only the click actions, but what exactly I need is to fetch the text displayed on the canvas. Help will be much appreciated, Thanks in advance.

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]")

In selenium python, I only one to click on the second button, assuming there are 3 of the same buttons

So I am automating a process and there are 3 of the same button on a single webpage. However, I only want to click on the second button. Is there anyway I am able to that?
Here's the code for the button":
expandButtons = driver.find_elements_by_xpath("//div[#class='expand-collapse']")
expandButtons[1].click will click 2nd button.

How to click a button that has no name or id elements

I am using selenium with python and i am clicking buttons with this command
loginbtn= driver.find_element_by_id('btnLogin').click()
My problem now is that i got 2 buttons with no name or id and with exactly same code as the photo below.
Is there any way to define that i want to click on Submit button or Cancel button?
Use the below xpath.
For submit:
driver.find_element_by_xpath('//button[./span[text()="Submit"]]').click()
For cancel.
driver.find_element_by_xpath('//button[./span[text()="Cancel"]]').click()

Selecting saveas button when downloading file from browser

I've written a code with selenium and pyautogui to click around on a website and be able to click the save button with pyautogui after the download button has been clicked with selenium. I wanted to know if it was possible to click the saveas button instead and change the file name with python.
the code I have:
driver.find_by_element_by_xpath("//a[#id='Ribbon.Library.Action.ExportToSpreadsheet-Medium']").click()
saveButton = pyautogui.locateCenterOnScreen("C:\\User\\Documents\\savebutton.jpg")
pyautogui.click(position[0], position[1])
so what this does is click the download button and then compares the picture of the button and clicks the save option. But theres an arrow on the button to click saveas and that's what I need to click so I can choose the destination to save it and change the name of the file. Was wondering if there is a way to do this.
the button looks like this
also I am downloading from Edge, I'm not looking to use chrome or any other browser.

Categories