I am building a Selenium Webdriver script in Python. My issue is that I am performing some actions that consist on moving to a certain position and clicking there. My action is not working, so I wanted to run the script as non headless to see what is happening, but, as the cursor does not appear in the screen, I am not able to see if my mouse is moving as I expected. Is there any way to enable seeing the cursor when running Selenium in a browser window? I am using Chromium but I am planning on adding more browsers to this script, so I would need something that at least works for Chromium, but it would be useful to have a solution for other browsers too. The code I have to move to the element and click it is this:
def scrollToCenter(driver, element):
# Get the height of the window
window_height = driver.execute_script("return window.innerHeight;")
# Get the position of the element relative to the top of the page
element_position = element.location['y']
# Calculate the position to scroll to
scroll_position = element_position - window_height/2
# Scroll the page to the desired position
driver.execute_script("window.scrollTo(0, {});".format(scroll_position))
# move the cursor to the element
actions = ActionChains(driver)
actions.move_to_element(element).perform()
def simulateClick(driver, el):
# Scroll to the point where the element is located
driver.execute_script("arguments[0].scrollIntoView();", el)
try:
# Move to the element and click it
scrollToCenter(driver, el)
el.click()
except Exception as e:
print(e)
Seeing the scroll being performed would also be useful.
Also, I'd like to know if I can store this test case's headless execution in a video, so that I do not need to watch the execution while it happens to check if the mouse is in the correct position or not.