No xpath click in selenium - python

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()

Related

Selenium - Element not interactable

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.

Can't click on webpage element using python selenium when used with mobile user-agent

I am trying to automate clicking on the play button of an embedded iframe music player on a webpage, I am coding using python 3 and Selenium to select the element to click.
When the user-agent is changed to replicate a mobile device, a wrapper layer then obscures the button that I can normally click, it asks if I want to listen on the main site or in the browser. I want to listen in the browser, but so far everything I have tried to click the correct element to achieve that, has failed.
I believe I am clicking on the wrong part but cannot find a way to access the correct part.
The inspect window of the browser shows the below for the part of the wrapper I need to click on:
<a class="mobilePrestitial__link sc-font-light" href="#">
Listen in browser
</a>
::before
"
Listen in browser
"
/a>
When I hover over the ::before part it highlights the part in the browser that I believe I need to click, but using right-click to inspect ::before just says 'scroll in view' so I cannot copy whatever the element represents.
My current code is this:
driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element_by_partial_link_text('Listen in browser'))
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//a[#class="mobilePrestitial__link"]'))
)
element.click()
But it errors without a message, I suspect I need to be clicking on the element presented by ::before but cannot figure how to do that.
I found a workaround and solved this by hiding the wrapper overlay using Selenium in python script to make a Javascript call
driver.execute_script('document.getElementsByClassName("mobilePrestitial")[0].style.display=\"none\"')
once the overlay is hidden with the above code, the original button is accessible in the browser

ElementClickInterceptedException: element click intercepted: [duplicate]

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'm trying to submit one form on wordpress plugin using selenium + python. When I press publish button , it is giving an error.
ElementClickInterceptedException: element click intercepted: Element
type="submit" name="publish" id="publish" class="button button-primary button-large" value="Publish"> is not clickable at point (728, 15). Other element would receive the click:
...
I have tried following solutions:
Used action driver, but it didn't work.
Used webdriverwait() function, it didn't work.
Used Xpath, CSS selector, ID - It's giving same error in all three.
` browser.find_element_by_css_selector("""#save-post""").click()
WebDriverWait(driver, 90).until(EC.element_to_be_clickable((By.ID, "save-post"))).click()
`
Note that when I run that specific line in python console, it is working. But while running the full script, it is showing error.
There are so many similar questions on portal but none of them worked. Kindly help me to solve this issue.
Ok, the answer is in error message - "Other element would receive the click: ..."
I had the same problem when I just started using selenium.
Couldn't figure out what's the problem. "Other element would receive the click: ..." means there is other element above(overlapping) your element(pop up window, page is grayed out or disabled while loading, Some JS running etc., so when Selenium trying to click on your element its actually clicking on that blocking element.
Selenium is running really fast and clicking before its become clickable, that's why u are not able to click on it - "when I run that specific line in python console, it is working" Try to click after time.sleep() 5-10 sec or run script with debug mode.
If this is the case then you can use wait or add condition before find your element to check that element that prevent from clicking on you element is not there then u click on your element.

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()

Python Webdriver need code to find and click a particular element

This is a similar question to one answered for me earlier.
I have used Python 2.7, Webdriver and Chrome to access Pinterest to insert images to a board. I have successfully logged in to the site and created a board. The problem that I have is to identify and click the “Edit Board” button successfully using xpath find elements code. I attach an image of the web page (see red arrow) and the Chrome inspect on the element. The code I have tried is:
driver.find_element_by_xpath('//span[contains(text(),"Edit board")]')
The result is enabled and displayed, however, click on the element gives the following exception:
WebDriverException: Message: unknown error: Element is not clickable
at point (131, 91). Other element would receive the click: <button
class="Button Module ShowModalButton boardEditButton btn hasIcon
rounded" type="button">...</button>
I cannot see any other find element option which will make the button unique.
I have successfully used the span text find on this website in one other place. It does not work for all buttons of this type, but, in those cases another unique tag qualifier works.
Web Page:
Inspect Element:

Categories