This question already has answers here:
Python and Selenium xpath for selecting with multiple conditions
(2 answers)
Closed 2 years ago.
I am trying to click this button but the problem is that the button class there is used multiple times within the website, span class is also used multiple times.
Classes
Haven't been able to find a proper tutorial on how to do it.
Any help on how to target this button to be able to click it?
If a class is used multiple times, you should use another method to get the element.
In selenium there is lots of methods to locate html elements
Locating Elements
There are various strategies to locate elements in a
page. You can use the most appropriate one for your case. Selenium
provides the following methods to locate elements in a page:
find_element_by_id
find_element_by_name
find_element_by_xpath
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector
The relevant documentation is here.
Related
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.
This question already has answers here:
How to handle the popup "Accepting all cookies" when the element is data-testid - Using Selenium in Python
(2 answers)
How to extract info within a #shadow-root (open) using Selenium Python?
(1 answer)
Closed last year.
How can we apply wait on shadow dom web elements using selenium webdriver?
The normal wait using the following code doesn't seem to work on shadow elements.
WebDriverWait(driver,15).until(EC.visibility_of_all_elements_located((By.XPATH,"/html/body/widget-commponent//div/div[2]")))
Kindly help if anyone knows how to do that.
Thanks.
This question already has answers here:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable when clicking on an element using Selenium Python
(6 answers)
How to resolve ElementNotInteractableException: Element is not visible in Selenium webdriver?
(6 answers)
Closed 2 years ago.
I am trying to click a button using selenium, i have attached an image of the html code.
so far i have:
browser.find_element_by_css_selector("input[type='radio'][id='SF_SP2_01']").click()
but get error saying:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
First, see if the advice in this link helps
However, if that does not help, the element you are trying to click may not be in the same frame you are currently in. Check for any < iframe> tags in the html, and if there is one the fix should be something simple like:
driver.switch_to.frame('iframe_here')
Then you will be able to interact with the element.
That is one possible solution, it may not be the correct one for this issue but give it a try.
This question already has an answer here:
How to send text to the Password field within https://mail.protonmail.com registration page?
(1 answer)
Closed 3 years ago.
Hello I am trying to work on a side personal project for automating email accounts. I am relatively new to Selenium and am having trouble clicking the signup button. I have tried the two following methods but none of them seem to be working.
driver.find_element_by_xpath('//*[#link= "https://protonmail.com/signup"]').click()
driver.find_elements_by_link_text('SIGN UP').click()
This is what I see when I click inspect element on the sign up button by the way. There is no id or value that can will easily classify the button.
SIGN UP
I think you can use tag+value selector.
driver.find_element_by_css_selector("a[value='SIGN UP ']").click()
You can use the href attribute like this
driver.find_element_by_xpath('//*[#href="signup"]')
You can also locate by the text, but you need to take the space into account, so use partial text
driver.find_element_by_partial_link_text('SIGN UP')
This question already has answers here:
Element MyElement is not clickable at point (x, y)... Other element would receive the click
(5 answers)
Closed 3 years ago.
I solved this issue with the following code, I didn't find a solution in other posts so I tried to make myself and worked just fine. I don't now if it's a good code because I'm new in Python and programming but it worked.
As I wanted to select the element using visible text (not by value or option number), I used the following code, which consist in finding the element by Xpath [contains(text(), 'text')] and then changing the html. Maybe it's useful for another one.
self.driver.execute_script(
"arguments[0].selected=true",
self.driver.find_element_by_xpath(
'//*[contains(text(), "%s" )]' % 'your_visible_text'
),
)
this issue usually occurs in chrome browser as chrome uses point location. this happens when element is loaded in DOM but postion not fixed on UI. There can be certains solutions you could use to fix this:
Wait:
Use of WebDriverwait and Expected Conditions classes.
Eg:
visiblityOfElementLocated(By locator)
or
visibilityOf(WebElement element)
we are waiting for element to be present and visible before performing action
try to maximise the browser window before selecting dropdown
driver .manage().window().maximize();
Hope this help. Code is using Java selenium please use its corresponding Python code.