Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriverException: Expected 'id' mouse to be mapped to InputState whose subtype is undefined, got: pointerMove

I have a problem with Selenium that I can't make sense of. Also, I can't find a lot of information about this problem via Google.

My Selenium script performs the following steps:

  1. Log into Facebook.
  2. Go to the list of friend proposals.
  3. Scroll down a few times (in order to load more proposals).
  4. Present all proposals one by one on the console and ask the user whether the friend should be added.

On confirmation, an Action chain is created that moves to the proposal in question and then the add button is clicked.

But the Action chain does not work. I get the following error:

Potential friend name: 'John Doe'
Social context: 'Max Mustermann und 3 weitere gemeinsame Freunde'
Traceback (most recent call last):
  File "c:\...\facebook_selenium_minimal.py", line 74, in <module>
    main()
  File "c:\...\facebook_selenium_minimal.py", line 57, in main
    friend_add_button).perform()
  File "C:\Python36\lib\site-packages\selenium\webdriver\common\action_chains.py", line 77, in perform
    self.w3c_actions.perform()
  File "C:\Python36\lib\site-packages\selenium\webdriver\common\actions\action_builder.py", line 76, in perform
    self.driver.execute(Command.W3C_ACTIONS, enc)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
    self.error_handler.check_response(response)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Expected 'id' mouse to be mapped to InputState whose subtype is undefined, got: pointerMove

This is my Selenium script:

import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait  # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC  # available since 2.26.0
from selenium.webdriver.common.action_chains import ActionChains

TIMEOUT = 5

def main():
    driver = webdriver.Firefox()
    driver.get("http://www.facebook.com")

    print(driver.title)

    input_mail = driver.find_element_by_id("email")
    input_password = driver.find_element_by_id("pass")

    input_mail.send_keys("[email protected]")
    input_password.send_keys("your_password")
    input_password.submit()

    try:
        WebDriverWait(driver, TIMEOUT).until(
            EC.visibility_of_element_located((By.NAME, "requests")))

        driver.get("https://www.facebook.com/friends/requests/?fcref=jwl")

        WebDriverWait(driver, TIMEOUT).until(
            EC.visibility_of_element_located((By.ID, "fbSearchResultsBox")))

        # Let Facebook load more friend proposals.
        for i in range(2):
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
            time.sleep(1.0)

        friend_proposals = driver.find_elements_by_class_name(
            "friendBrowserListUnit")

        for friend_proposal in friend_proposals:
            try:
                friend_title = friend_proposal.find_element_by_class_name(
                    "friendBrowserNameTitle")
            except NoSuchElementException:
                print("Title element could not be found. Skipping.")
                continue

            print("Potential friend name: '%s'" % friend_title.text)

            social_context = friend_proposal.find_element_by_class_name(
                "friendBrowserSocialContext")
            social_context_text = social_context.text
            print("Social context: '%s'" % social_context_text)

            friend_add_button = friend_proposal.find_element_by_class_name(
                "FriendRequestAdd")

            actions = ActionChains(driver)
            actions.move_to_element(friend_proposal).move_to_element(
                friend_add_button).perform()
            time.sleep(0.1)

            print("Should I add the friend (y/N): ")
            response = input()
            if response == "y":
                friend_add_button.click()
                time.sleep(1.0)
                print("Added friend...")

    except TimeoutException as exc:
        print("TimeoutException: " + str(exc))
    finally:
        driver.quit()

if __name__ == '__main__':
    try:
        main()
    except:
        raise

I'm using the latest Selenium version:

C:\Users\Robert>pip show selenium
Name: selenium
Version: 3.3.1

And I have Firefox 52.0.1 with geckodriver v0.15.0.

Update: A quick test revealed that the same script works flawlessly with the Chrome Webdriver.

Update 2: This issue in the Selenium bugtracker on Github might be related: https://github.com/SeleniumHQ/selenium/issues/3642

like image 701
robert Avatar asked Dec 29 '25 14:12

robert


1 Answers

I ran into the same issue today. You might have observed that the first move_to_element and perform() worked - at least this was true in my case. To repeat this action, you should reset the action chain in your for loop:

actions.perform()

actions.reset_actions()

like image 192
roxx0r.munich Avatar answered Jan 01 '26 15:01

roxx0r.munich