I am trying to solve a google captcha with Selenium, using python
I'm using this simple example site to test with, but I am having difficulties understanding how to select a button that is within a shadow root.
This image shows the button element I need to get.
I understand I need to get the outer div element first, then search for the inner element, but I'm failing to do so, as I am not 100% clear on how to navigate to the inner element after executing something like
driver.execute_script("return document.querySelector('div[class=\"button-holder help-button-holder\"]')
This question is on similar (same?) problem, but there is no working solution.
Related
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
So I'm coding this bot to join my school classes for me using selenium and I'm facing this issue where it goes to my conferences page and it waits for a join button to appear and press on it. At first, it wouldn't be able to find it so I scratched the idea of time and I made sure that when it opens the page the join button will be there so I did that and even put this line of code just to make sure
join=WebDriverWait(driver,30).until(EC.presence_of_element_located((By.XPATH,"//span[contains(text(),'Join')]")))
yet it still can't find the join button either press it even though it's visible by the eye I will link the page source under in a link if you can just tell me how to find it also I cant use the href method since it isn't stored like that it's just stored like this
https://i.stack.imgur.com/ldxY7.png
so I'm really confused it's almost like this is an invisible element its funny because even when I do get an error I use control F on inspect element to check if I used correct XPATH and I always find it so I don't see why selenium cant please help I think I just missed something I just don't know what.
Page Source
Check the presence of the element by looping and checking the presence_of_element_element_located multiple times with 2/3 seconds delay added between every consecutive check.
An analogy from python selenium-
for i in range(5):
l= driver.find_element_by_css_selector("#js-gdpr")
time.sleep(5)
OR
Iterate over all the elements under the parent div and verify it using unique text/color and access it.
I think you are trying to do Google meet automation. In that website the "join now" button is declared as a dynamic path so, you can use the library pyautogui
impor pyautogui as pg
for i in range(5):
pg.press('tab')
time.sleep(2)
pg.press('enter')
This code will help you to find the join now button and to click it.
I am trying to click the search button in this link here
I would like to click the search button and then download all URL's on the next page but currently it is finding monthly list
The link below takes you to a screenshot of my code where it outputs the monthly list button instead of searcj/
Python code selenium
Welcome to Stack Overflow!
You can use the .click() method to click an element object, and the .find_element_by_xpath() method to find the element. I've located that the element's full XPATH is /html/body/div/div/div[3]/div[3]/div/form/fieldset/div[5]/input[2].
You can implement all the pieces together like so:
driver.find_element_by_xpath("/html/body/div/div/div[3]/div[3]/div/form/fieldset/div[5]/input[2]").click()
if you are starting I recommend you using some extension to help you find the xPath of the elements.
I used Xpath Helper from Chrome, but you can use any other.
The Xpath of the Search button is:
/html[#class='js']/body/div[#id='idox']/div[#id='pa']/div[#class='container'][2]/div[#class='content']/div[#class='tabcontainer']/form[#id='weeklyListForm']/fieldset/div[#class='buttons']/input[#class='button primary']
After you have the XPath you can use it in the selenium driver to find the elements.
This can be enough, but I recommend you to learn in depth how this works to know exactly what it is doing.
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?
There are two dropdown element code: one is standard option-select and the other is made of div, ul, li elements.
And somehow both are used to select a dropdown element via javascript...
Problem is selenium is not able to click the element and throws not visible exception.....
See the dropdown box here: [Its below "Top 5" tab]
http://www.oddsbox.com/baseball/mlb/record/section.odd
Following solutions don't help either:
Python Selenium: Find object attributes using xpath
selecting element in python selenium
Selenium nested li div menu select() or click() python
how to select custom dropdown list element from selenium
It would be nice if you'd post your code, so we can see a bit clearer what's happening.
Also admitted, I did not check all of your links to see everything that doesn't work. However my guess is this:
If you get an ElementNotVisible exception, then you should probably make your element visible before selecting it.
In this case I'd forget about the selecting commands and all and just :
- click on the element to open and reveal the menu and then
- click on the desired element inside that list.
Looks something like :
driver.find_element_by_xpath(".//*[#id='ctmSelectBox4_wrap']/button").click()
driver.find_element_by_xpath(".//*[#id='ctmSelectBox4_wrap']/div/ol/li[6]/label/span").click()
I personally detest these ugly xpaths (especially for maintainability), and probably would change that somehow, but that's not the scope of this question.
Hope that helps!