Selenium - Element not interactable - python

Needing help on this problem. All solutions/suggestions I have researched do not fix it.
Trying to click a button with Selenium. Keep getting these errors.
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: [object HTMLButtonElement] has no size and location
and selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I am not understanding why this element is not interactable.
play_button = driver.find_element_by_xpath('//*[#id="ppp"]/div/div[2]/div[2]/div[2]/button')
driver.implicitly_wait(10)
ActionChains(driver).move_to_element(play_button).click(play_button).perform()
When printing play_button = <selenium.webdriver.remote.webelement.WebElement (session="ca50b37ee2e4b194b2ad5305e254079f", element="78e35dc3-fef8-4082-a6e4-0a92dfbf2ec6")>
I have tried WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[#id="ppp"]/div/div[2]/div[2]/div[2]/button'))) but this times out. Element never becomes clickable.
I have tried using the full xpath.
I have tried disabling extensions/maximize window driver options.
The element is not in a frame or anything. It lies in a div that lies in the body.
The element is clickable within Chrome's console.
Any information/suggestions would be helpful.
Thanks.

The button you are trying to click is hidden, not clickable even with JavaScript executor.
You can start video on that page clicking on
driver.find_element_by_css_selector('div.player-poster.clickable').click()
or
driver.find_element_by_css_selector('div.play-wrapper').click()
No need to use ActionChains(driver).move_to_element etc.
Just a simple click.
Just don't forget setting
driver.implicitly_wait(10)
Or using an explicitly wait of expected conditions to make page loaded before accessing the element.

Using full XPath solved this problem for me.

Related

selenium-driver :looking a solution for locating and clicking a button when i open google page

python selenium driver:
No thanks
when i open a google page the, there is a small window asking if i want to sign in or not. i want to click on "No thanks" button, which is as shown above.
i have tried these methods so far, but i keep getting errors. None of the following is working.
#self.driver.find_element(By.CSS_SELECTOR, 'button.M6CB1c')
#button=self.driver.find_elements(By.XPATH, '//button')
#abc=self.driver.find_elements(By.NAME, 'ZUkOIc').click()
#self.driver.find_element(By.TAG_NAME, 'button').click()
error message for the 1st line of code:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".M6CB1c.rr4y5c"}
selenium.common.exceptions.NoSuchElement is caused when the element is not in the page at the current time.
TLDR;
What you're looking for is Explicit Wait in selenium. You need to use WebDriverWait with expected condition element_to_be_clickable.
When we load a page, modern pages tend to load javascript that can often manipulate DOM (html page objects). The proper way to handle this is to wait for the page or the required element to load, and then try to locate it.
The selenium waits section explains this very well with an example.
You should try this :
driver.find_element(By.XPATH, '//button[#id="W0wltc"])

Unable to click on visible Search icon - Selenium Python (Geckodriver)

I am not able to click on a visible Search button (Selenium - Python, geckodriver). Tried ID, XPATH and CSS, none of the options work.
Below is the message for Xpath
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //img[#id='pageToolbar_search_image']
Anyone faced similar problems?
Script:
Searchicon=driver.find_element(By.XPATH,"//img[#id='pageToolbar_search_image']")
Searchicon.click()
Code:
There may be several reasons. Most likely you did not wait for the appearance/rendering or use the wrong locator
If you can find an element by xpath using devtools, then time.sleep() may help, use it before trying to find the element
https://selenium-python.readthedocs.io/waits.html

No xpath click in selenium

I've written a "Lovoo" bot with Python and Selenium and I'm almost done.
Now I have the following problem:
When the bot clicks on a user, a window opens. To exit this window, the bot has to click outside of it.
But from that point on all the source code has changed and I have nowhere to xpath or click with selenium. I simply can't get any xpath that works.
I tried
WebDriverWait(DRIVER,10).until(EC.element_to_be_clickable((By.XPATH,'//body[1]')))
DRIVER.find_element_by_xpath('//body[1]).click()
But the click is only working randomly and rarely.
Error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div class="thumbnail thumbnail-square u-margin-0">...</div> is not clickable at point (370, 497). Other element would receive the click: <div class="absolute-fill text-left" ng-transclude=""></div>
(Session info: chrome=96.0.4664.9)
I don't want to use
action.click()
because then I won't be able to use my mouse for other things.
If I understood it clearly, you are trying to click on co-ordinate rather than a web element.
If this is the case then you can define an offset like below and try to click on it.
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_by_offset(10,10).click().perform()

Unable to locate element with Selenium on a website

i am trying to go to a certain website with selenium and click a button to load data then download csv file, I have tried using id,Xpath, class by I am still getting an error: any hint will be helpful.
here is my code below:
from selenium import webdriver
driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://eatradingacademy.com/software/forex-historical-data/')
driver.find_element_by_id("webpushr-deny-button").click()
driver.find_element_by_class_name('text-center')
here is the error i am getting:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".text-center"}
(Session info: chrome=91.0.4472.124)
I think the error is due to the button you're trying to click is wrapped inside an iframe.
Typically, you will have switch to an iframe in order to access elements inside it.
Try
driver.switch_to.frame(driver.find_element_by_id('data-app-frame'))
This will switch the webdriver to the iframe having id data-app-frame
Now try clicking your button using driver.find_element_by_id('btn-load-data')
This should work.
Here I am accessing the same button you tried to access in the question. In the question you are trying to access parent div instead of the button element itself. It is recommended to access the actual element instead of it's parent
You can learn more about frame switching here

Locate "file upload" button with Selenium

I have the button shown below (image and HTML) and am trying to click it.
Selenium is unable to locate it - I have tried locating by both xpath and by ID.
<input id="wsUpload1" type="file" name="file">
XPATH:
element = driver.find_element_by_xpath('//input[#id="wsUpload1"]')
element.click()
Where am I going wrong?
EDIT: Here is the exception thrown by Selenium:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[#id="wsUpload1"]"}
Possibilities
Duplicate web element with same id in the page.
Element may be in frame. You need to switch to frame
Trying to access the web element before page is loading.Give some wait time.
Not sure why your button wasn't found, maybe it's because of quotes (although it should show you error in that case), try with driver.find_element_by_xpath(".//input[#id='wsUpload1']") and see if it works. I'm not sure is your button already rendered on the page or you trigger it somehow so it's not there yet?
NoSuchElementException is thrown because your targeted element couldn't be found on that page, it could be that you are on the wrong page, element is not rendered yet so you should wait for it to appear, element could be in some iframe etc etc, it's hard to say when I don't know how your page works.
But if you are trying to upload something you should perform sendKeys() on that button (with path of file which are you trying to upload), not click() on it. This is how selenium upload works.
I have solved it - the driver opens a tab on a side panel and the button is in the tab. There seems to be a few ms delay between clicking the tab and the button appearing so I added a wait until element is clickable and that seems to work.
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[#id='wsUpload1']"))).click()

Categories