Q: Selenium - How to click on an 'unclickable' element I am using selenium with Python for browser automation. 
On this particular webpage, I need to select the categories for my uploaded video. The categories are shown to have checkboxes to be clicked, but in reality, they are not checkboxes. On clicking them by mouse, the class of the element changes.
Before-
<span class='foo', id='bar'>
After-
<span class='foo.active', id='bar'>
I am able to locate the element by using both find_element_by_class_name and find_element_by_id
The problem is not in locating the element, but in clicking on them.


*

*I have tried .click() method, which does not work obviously

*I tried ActionChains which gave an error that 



rect is undefined.



*

*I have tried execute_script method which does not throw any error but also does not change anything.


driver.execute_script("arguments[0].setAttribute('class','foo.active')", element)
Is there any other method to CHECK that checkbox?
Update: I have realized that the element is not in view as it throws an error

Message: Element  could not be scrolled into view

Also, element.text returns an empty string.
When I see the webpage in the browser, nothing is blocking the view.
Here is the code:
<li id='categoryID1' class='categoryBtn list5'>        
<span class="categoryCheckbox"></span>
<span class="categoryLabel">Funny</span>
<div class="reset"></div>
</li>

I tried:
driver.find_element_by_xpath("//span[contains(text(),'Funny')]")
It throws this error:

selenium.common.exceptions.ElementNotInteractableException: Message: Element  could not be scrolled into view

Update 2: I have also realized that using the contains(text()) method returns an element which is not in view. On the other hand, when I copied the XPath from the browser and then used the same, it returns an element which can be clicked.

A: Perhaps this will help:
elem = driver.find_element_by_xpath("[contains(@class, 'foo')]")

elem.click()

elem.send_keys(u'\ue007')  (or elem.send_keys(u'\ue00d') )


A: If the class is unique but dynamically changing, you need to search and take partial static value from that class.
In your case, you can try 
xPath = "//span[contains(@class, 'foo')]"
element = driver.find_element_by_xpath(xPath)
element.click()

and if there are multiple matches then you can use the matching index number like below :
(//span[contains(@class, 'foo')])[Matching index number]

for example, if you are getting match at index number 3 then you can do like below :
xPath = "(//span[contains(@class, 'foo')])[3]"
element = driver.find_element_by_xpath(xPath)
element.click()

Try to give some delay if the element is present and if you are getting any exceptions while clicking :
from time import sleep

sleep(3)
xPath = "(//span[contains(@class, 'foo')])[3]"
element = driver.find_element_by_xpath(xPath)
element.click()

I hope it helps...
