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.
Related
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!
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.)
I have a Python 2.7 script that should cast mp3 audio from Windows 10 to Chromecast audio devices through Google Chrome browser.
It does the following using Send Keys (keyboard and mouse automation) from the PyWinAuto module:
Open Google Chrome maximized
Click the "Customize and control Google Chrome" menu on the right
Selects "Cast.."
Selects a casting group
Inputs local address of mp3 in the address bar and hits Enter
It involves using time.sleep() a lot and has many problems as an experienced programmer would imagine. So I'm looking for a pythonic way of accomplishing the same result.
P.S: A cross-platform solution is much appreciated (especially for Raspberry Pi). And I can learn anything you suggest, even if it's not Python. Thank you
I've been working with selenium in Python recently.
I was curious if anyone has had experience with recording an instance of a headless browser? I tried finding a way to do this, but didn't find any solutions in Python - a code example would be excellent.
Some tips would be helpful.
I don't think they have any built in way to do this with any of the browsers. Your best bet would be to connected to the same instance of the browser (this is easier if you use the grid server) from another program then just take screenshots at short intervals.
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()