How to record video with Selenium python - python

I want to record a video of a few seconds (or gif) of a web page, I tried to take screenshots but the problem is that selenium takes too much time to make them (5 in 2 seconds). So I'm looking for a way to shoot the page.
I didn't find any recent tool, in fact the only programs doing it are on python2.
If someone has a way, I'm interested!

Related

How to scrape/automate an everchanging webgame using selenium?

I'm trying to automate a Webgame using selenium.
the problem that I have is the game is fast paced and needs to be interacted with otherwise you will loose the game and will be redirected to a different page.
So I never have enough time to properly analyze the HTML elements and write the code. is there any way to pause/save these interactions?
my other option is to just use OpenCV / image recognition
I have no idea where to start

Youtube + Selenium ChromeDriver (Python) - How to loop youtube video?

Already searched related questions but can't get solution.
How to use Python Selenium ChromeDriver to loop Youtube video?
Thanks a lot!
It MIGHT be useful for your purposes since it's not quite clear.
Once the video starts playing, right-click on the video screen and selects the option Loop.
As follows:
https://giphy.com/gifs/xUSGPLMaJQaEnkcwTR/html5
However, it may be not enough because after the video repeats itself for a while (approximately 20x) it just goes to the next video.
A workaround is to use javascript in the browser itself.
After click on Loop, open chrome dev tools console and type the following into it:
document.getElementById("loop").nextSibling.__shady_native_nextSibling.childElementCount = 2
The value here is arbitrarily and I cannot explain why, I only know that it should be greater than 1.
Doing so, the video should repeat itself indeterminately.

Selenium ActionChains simulated mouse control with Python is 10x slower than simulated keystrokes - why is this, and is there a better way?

I'm building a Selenium ActionChain via Python to hold and execute keyboard and mouse input. When the ActionChain only contains several keystrokes (through action.key_down() or action.key_up()), it executes in well under 0.01 s. As soon as I add a single cursor movement (using action.move_by_offset()) the execution time shoots up to 0.3-0.4 s.
First off, what's the technical difference that makes the mouse input so much more expensive?
Is there any better Selenium-based alternative, or should I be using a different tool for realtime browser input?
(For context, I'm using Selenium to run a reinforcement learning model on HTML5 multiplayer web games, so I need to execute actions as quickly as possible or my bot's reaction time suffers. I'm using the Firefox webdriver - I also tried Chrome, but found the geckodriver to be about twice as fast for mouse input. Ideally, I need to get all of my input execution to run in about 0.01 s so it doesn't slow down my model.)
If anyone is still looking for a fix here is what I did:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver, duration=10) # duration in milliseconds
actions.move_to_element_with_offset(website_element, x, y).perform()
I found this out from looking a bit in the source and seeing a duration argument that was left on the default of 250 ms. Does anyone know why they do this?
I dont know the answers to your other questions though
I still can't answer why the issue exists beyond orde's note above, but I did find that Selenium doesn't seem like the best tool for this, and was able to (somewhat crudely) work around it using additional libraries.
For anyone else with a similar need:
I ended up using D3DShot for video (much faster frame grab than Selenium) and PyAutoGUI for much faster mouse control (closer to 1 ms). I still utilize Selenium, but only to navigate to the site, log in, and put the game window in full screen.
Unfortunately this setup effectively prevents multiple bots from running on the same machine (you might be able to hack something together with one bot per display, but that would get pretty messy.)

How to click on a video using Selenium

I'm new to coding using python and it's libraries, and also new to stackoverflow so I apologize if I'm not acquainted to some things.
Anyway to the question. I'm trying to write code that automates playing a video from the website that. Here's an example link:
http://www.shush.se/index.php?id=164&show=southpark
I've tried these methods:
driver.find_element_by_id("playerload").click()
driver.find_elements_by_xpath("./html/body/table/tbody/tr/td/div[#id='load']/div[#class='player']/div[#id='playerload']/div[1]")
But nothing happens. The program exits without error but the video does not
start playing.
I tried clicking a the id "jw6playerid5040619_wrapper" but the number associated with that changes every time a page loads.
Any advice? Thanks in advance!
Even though you don't know the exact id, you know that it will start with "jw6playerid". The following works for me:
elements = driver.find_elements_by_xpath("//*[contains(#id, 'jw6playerid')]")
elements[0].click()

Any possible way to save webpage state to HDD?

Essentially what I want to do is be able to click a button and have the webpage state be stored somewhere on the HDD so it doesn't need to just sit in RAM, and when it's loaded again at some later time the page pops up exactly as it was before as if it had never been closed without the need to download anything over the internet to restore it (although additional resource requests that didn't exist when the page was saved should still download properly).
(as an example, firefox does this when it crashes, all the tabs are restored, text you've typed is still in the textboxes, etc..)
I don't care if that button is in a firefox plugin, chrome, or even a custom browser that I program myself with something like webkit perhaps.
I've been trying for days to find a way to do this. I made WebKit programs in both C++ and Python but every time I think I'm getting close there is some deficiency in webkit or a build-in security measure that prevents me from doing this. I tried creating MHTML archives but they don't allow javascript to download new data over the internet, I tried pickling the entire WebKit.WebView object in python, I tried looking through webkit code to see if I could patch the behavior into the source code myself
I'm running out of ideas and the only one I see left is to just post this online. Is there any way that I can do this, in any programming or scripting language, using any libraries at all?
I just have no idea where to turn next.

Categories