Home > Software engineering >  No xpath click in selenium
No xpath click in selenium

Time:10-21

I've written a "Lovoo" bot with Python and Selenium and I'm almost done.

Now I have the following problem:

image

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.

CodePudding user response:

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