How move to toolbar of browser [selenium] [python]

Question:

Please tell me how I can move the cursor to the toolbar of browser to see a popup modal window (https://the-internet.herokuapp.com/exit_intent)

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By


class TestExitIntent:

    def setup_method(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://the-internet.herokuapp.com/exit_intent')
        self.driver.implicitly_wait(5)

    def test_exit_intent(self):
        action = ActionChains(self.driver)
        action.move_by_offset(150, 0)
        action.perform()

        self.driver.find_element(By.XPATH, "//div[@class='modal-footer']/p").click()
Asked By: Polina

||

Answers:

Unfortunately this can not be done with Selenium / ActionChains.
There are multiple existing questions about this saying this is not possible.
In Java we can do that with external framework called Robot imported from java.awt.*
With Python this probably can be done with PyAutoIt but I’m not sure about this.

import pyautogui

pyautogui.moveTo(150, 150)
Answered By: Prophet
  • If cursor was not directly in workspace after the start of test, then test failed.
    @prophet
class TestExitIntent:

    def setup_method(self):
        self.driver = webdriver.Chrome(executable_path='D:WORKPycharmProjectswhat_can_I_dochromedriver')
        self.driver.get('https://the-internet.herokuapp.com/exit_intent')
        self.driver.implicitly_wait(5)

    def test_exit_intent(self):

        action = ActionChains(self.driver)
        #action.move_by_offset(550, 550)
        action.w3c_actions.pointer_action.move_to_location(550,550)
        action.perform()

        pyautogui.moveTo(100, 100)

        self.driver.find_element(By.XPATH, "//div[@class='modal-footer']/p").click()
Answered By: Polina