Uploading an image with Selenium in Python [duplicate] - python

This question already has answers here:
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard: while sending text to FirstName field in Facebook
(5 answers)
Closed 2 years ago.
I'm trying to automate uploading a picture on this website.
I tried locating the element and sending the image path.
UploadBtn = b.find_element_by_xpath('/html/body/div[5]/div[2]/div/div/div/div[2]/div/div[2]/div[1]/button[1]/div/div[2]')
path = 'imagepath'
UploadBtn.send_keys(path)
But the problem I'm getting is this:
selenium.common.exceptions.ElementNotInteractableException:
Message: Element <div class="action-button-text"> is not reachable by keyboard
Is there any other way to do it? Or am I doing something incorrectly? Also, please ask me if you want more details about the problem.

I think you just should click the button next
using the UploadBtn.click() method

Related

Apply Wait on shadow DOM Selenium [duplicate]

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.

Selenium find an element and check if it's interactable [duplicate]

This question already has answers here:
ElementNotVisibleException: Message: element not interactable error while trying to click a button through Selenium and Python
(2 answers)
ElementNotVisibleException: Message: element not interactable in Robot Framework
(4 answers)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable using Selenium
(1 answer)
'ElementNotVisibleException:element not interactable' error locating Google Search button even though element was waited for on Google Home Page
(3 answers)
Closed 2 years ago.
This is my code:
label = browser.find_elements_by_xpath('//label[contains(.,"{}")]'.format("XYZ"))
if label:
check if we can click this element (label[0]) if it's not clickable, continue.
Is it possible to find an element and then check if it's clickable?.
Normally this issue happened with webpages where when click button something else appeared. This means that element exists BUT you can't interact with him. How to handle this error or ignore and continue?
P.S. Similar question already asked several times, BUT I can't see the answer which will fit my needs. Solutions like implicitly_wait(1) and e.t.c. are not what I'm looking for.
I have used .is_displayed() which solved my issue.
Find element x
x[0].is_displayed()
if True carry on

Trying to click radio buttons using Selenium using python [duplicate]

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.

Not able to locate element, not iframe or page load [duplicate]

This question already has answers here:
Unable to locate element of credit card number using selenium python
(2 answers)
Closed 3 years ago.
I am attempting to automate the checkout process of a shopify checkout and selenium can't seem to find the elements necessary to complete the checkout. NOTE: This checkout is not in an iframe and i have done extensive research to make sure that the page is fully loaded, so this is not a duplicate question.
try:
elem = driver.find_element_by_id('number')
elem.send_keys('4342923222931029')
except NoSuchElementException:
assert 0, "can't find input with number id"
Here is what i am trying to access: screenshot of the source code of the checkout code
Here is the python code to switch to the correct frame.
ele = driver.find_element_by_xpath("//iframe[contains(id, 'card-fields-number')]")
driver.switch_to.frame(ele);
For Java solution refer here

Login to Gmail with Selenium Webdriver [duplicate]

This question already has answers here:
Log into gmail using Selenium in Python
(2 answers)
Closed 5 years ago.
I'm trying to automatically log into Gmail via a Python script. I'm using the selenium webdriver. I've managed to get my email entered but I don't know how to get my password entered as well. I've already checked past questions on here but the selectors mentioned in the answers don't seem to work. I keep getting an "Unable to locate element" error.
The code I tried:
driver.find_element_by_name("password").send_keys(pw)
You can use wait before if wanted otherwise you can achieve this simlply by ID
Gpassword = driver.find_element_by_id("password")
Gpassword.send_keys("xxxxxxxx")
This should be a comment but I don't have the 50 required rep.
I would try the GMail Python API. It should be a lot easier:
https://developers.google.com/gmail/api/quickstart/python
Make sure the element name is correct
make sure the element is visible (not overlapped by another element. ex: by virtual keyboard (in mobile application) or by auto-complete box)

Categories