Trying to scrape a href with Chromedriver? - python

I'm building a lookup tool to automate some of my work and have ran into an issue. One of the buttons I need it to press opens a new tab each time it is clicked. I plan on looping through this 15-30 times, and do not want a million tabs open. Is there any way to scrape the href from that button so that I can just navigate to it directly? Its fine if its a bit inefficient time wise, as this will be going in the background while I do other things.
currently:
button = wd.find_element("xpath" ,'xpathhere')
wd.execute_script("arguemnts[0].click()", button)
but I do not know how to pull the href from the button and am not having luck finding it online. Thank you!

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.

Wait for an element to appear, instead of keeping on refreshing the page using selenium

I am using selenium webdriver, python to write a test case wherein I have to perform an action when a button appears on the screen. The tricky part over here is that if the button is not already present, I have to keep on refreshing the page till it comes and then perform the necessary actions.
I wanted to know if there's any other way around this so that I won't have to keep on refreshing the page?
Thank you for the help.

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

Clicking multiple <span> elements with Selenium Python

I'm new to using Selenium, and I am having trouble figuring out how to click through all iterations of a specific element. To clarify, I can't even get it to click through one as it's a dropdown but is defined as an element.
I am trying to scrape fanduel; when clicking on a specific game you are presented with a bunch of main title bets and in order to get the information I need to click the dropdowns to get to that information. There is also another drop down that states, "See More" which is a similar problem, but assuming this gets fixed I'm assuming I will be able to figure that out.
So far, I have tried to use:
find_element_by_class_name()
find_element_by_css_selector()
I have also used them in the sense of elements, and tried to loop through and click on each index of the list, but that did not work.
If there are any ideas, they would be much appreciated.
FYI: I am using beautiful soup to scrape the website for the information, I figured Selenium would be helpful making the information that isn't currently accessible, accessible.
This image shows the dropdowns that I am trying to access, in this case the dropdown 'Win Margin'. The HTML code is shown to the left of it.
This also shows that there are multiple dropdowns, varying in amount based off the game.
You can also try using action chains from selenium
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav # submenu1")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
Source: here

Python - How to find an element in Selenium Webdriver by its sibling content?

I am currently developing an webdriver automation tool to perform a task in which I have to interact with a huge amount of elements. To do so, I am using Python 3.6.3, Selenium and Pandas.
One of these elements occurs to be a button that appears multiple times in the same screen. The problem is, only one of those buttons is the one I have to click on and there is no difference between them, except for its xpath (which changes everytime the page is refreshed).
The only way to know which one is the correct is by identifying the text contente of its simbling elements, which describes what the button in supposed to do. I managed to reach this element using:
element=driver.find_elements_by_xpath("//*[contains(text(),'"+textvariable+"')]")
But now I am stuck! How can I tell Selenium to click the button knowing only the text contente of its sibling?

Categories