fsaa
fsaa

Reputation: 133

Is there any way to click on "plain text" using selenium?

Apologies if this question was answered before, I want to click on an area in a browser with plain text using Selenium Webdriver in python

The code I'm using is:

element_plainText = driver.find_elements(By.XPATH, '//*[contains(@class, "WgFkxc")]')
element_plainText.click()

However this is returning "ElementNotInteractableException". Can anyone help me out with this?

Upvotes: 0

Views: 588

Answers (1)

Dylan Lacey
Dylan Lacey

Reputation: 1844

Selenium is trying to be helpful here, by telling you why it won't click on the element; ElementNotInteractableException means it thinks that what you're trying to click on isn't clickable.

This usually happens because either:

  • The element isn't actually visible, or is disabled
  • Another element is "overlapping" the element, possibly invisibly
  • You're clicking something Selenium thinks won't do anything, like plain text

There's two things I'd try to get around this. Firstly, Actions. Selenium has an Action API you can use to cause specific UI events to occur. I'd suggest finding the co-ordinates of the text, then making Selenium click those co-ordinates instead of telling it to click the element. Read more about that API here.

Secondly, try clicking it with Javascript, using a Javascript Executor. That can often give you the same outcome as using Selenium directly, without it being so "helpful".

Upvotes: 1

Related Questions