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
Related
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 started getting into python web automation(with chrome). I am using python 3 and selenium module. Is there a way of having the recaptcha pop up in a seperate window allowing me to solve it like normal and then carrying on with my set automation?
Any advice is much apprectaited
Thanks
Image of captcha
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.
I've been using the 'win32api' module with Python to emulate keyboard and mouse controls in order to make simple bots to do little tasks, like spamming my friends on Skype or cheating in flash games.
Now I wanted a way to do something similar, but rather than emulating keyboard commands to play on a webpage, it would send the data to the webpage directly. For example, I may want to make a program that browses a forum searching for times people use a certain key-phrase or key-word, then responds. I could do this by emulating keyboard and mouse commands, but I wouldn't be able to use the computer while it was running, plus it would be extremely difficult to get it to read the words straight off the webpage.
I was wondering if anyone knew of any module that allows you to send simple data to a webpage to do small tasks, such as filling in a form or clicking a hyperlink?
If an example could be provided too, that would be helpful.
You can try mechanize library - https://pypi.python.org/pypi/mechanize/
It gives you DOM-level page manipulation (you can select particular forms, fill them in, submit data etc), can navigate/submit forms, handle cookies and do many things and I think this is just what you want - behaving just like typical user.
I used it for my bot to process through facebook OAuth and it did just fine.
I am trying to run a headless browser, to which when I pass a URL simulates the entire webpage as it would if run from any of the popular browser. Importantly it must manage to run Adobe Flash Player (and hence flash videos). I have heard things about selenium webkit but I am not sure about its capabilities as I have never used it especially when it comes to handling flash content.
Infact if I were to narrow down the problem, I just want to run a flash content in a web site but out of the internet browsing window under my program (preferably python). If this is possible can someone point me the right approach. Do let me know if any further clarification is needed in the question.
Give a try to http://phantomjs.org/ it works great with a headless webkit and flash.
You could look at http://jeanphix.me/Ghost.py/ to control phantomjs with Python.