Gain colour of a known coordinate on screen in python - python

I'm trying to automate a specific task using python. I need to execute a specific task when a specific colour pops up on the display. For example:
During the automation process, when the code to open a web browser is executed and a web browser pops up,I need to make sure that it actually worked, by detecting the colour at the exact coordinate where the logo of the browser is situated. So that it confirms the browser is open, then I need to use that information to execute another code.
As we know, when we try to open a browser, there will be a lag to open up the browser. Since that lag will be different, I need to execute the next code only after opening the browser.
I have gone too far with my explanation, but if you got any idea from what I have just explained, please help me with what you know?

Related

Why does the Selenium's program always automatically jump to my desktop

I make a automated crawler for python-selenium but it's always automatically jump to my desktop.
Is it because I recycle swicth to window()?
Please tell me why?
To perform any action within the AUT(Application Under Test) Selenium needs to focus on the elements.
Due to the focus on the Browsing Context, itjumps to the foreground of your desktop.

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.

How can I program a macro that will do the clicking for me in a web game?

I'm currently playing Mr. Mine and I'm lazy to click 'sell' every 1~2 minutes.
I could use a mouse macro program that I can make the computer to do the clicking for me but this sounds like an inelegant method.
I was thinking about some way I could make a code that will hack into the web browser with the web game on and somehow send some kind of 'request' to the server that will sell the minerals.
I mean, after all, clicking it by hand eventually will send some request to the server so why not do this sending through a preprogrammed code?
I know my question is broad, so let me ask a few questions that will give me a lead to start on my project.
What to I need to learn to understand the 'sending request' part?
Is there anyone or any script that has already done what I want to do?
I'd like to take a look at the source code. (it's okay even if its not Mr.Mine. any other web game would also be of help)
Also, I'm currently interested in python so if there's any example in python, I'd be really thankful.
update: "I've solved the problem"
I'm just writing how I solved the problem just in case some other folk who just started Mr.Mine faces the same laziness that I did.
As it turns out, Mr.Mine doesn't actually exchange packets with its server. It only uses internet connection for initial loading of images and all that.(I think it is..)
If you right click on the Mr.Mine web page and view the html code of it, you'll find that its full of javascripts.
After roughly reading through these javascripts, my theory that this game doesn't rely much on packet data became more persuasive.
Anyway that's why I approached my problem at a javascript perspective and I finally got a solution
What you need to do is utilize chrome's developer tools.(I'm a chrome user)
You can access to this tool also simply by: from the mr.mine web page, right click anywhere -> click the very last button. Then you'll see some panel popping up at the bottom of the screen.
this tool enables you to fiddle with the html code or javascript in it.
I'm not good at this either since this is my first time actually using it for a practical purpose.
I just managed to scrape enough knowledge about this by googling to satisfy my needs.
In this new panel, at the top menubar, there's the 'Console' tab on the very right.
Click this and you'll see a command console.
This is where you can execute java commands within the javascript of the webpage.
Well from here, its strictly 'Mr.Mine' related.
From my previous rough reading of the javascript, I found that the sell buttons have been given the ID such as 'SB2', 'SB3', 'SB4', and so on.
So what I did was just type
setInterval(document.getElementById("SB2").onclick, 300);
at the command line and pressed enter.
this command will automatically press the SB2 button(which corresponds to 'Coal') every 0.3 seconds.
*Caution: you must have the 'selling' page opened when this code is executed. I found out that if the 'sell' page is not opened, the code doesn't work.
*Caution2: another funny thing is, even within the 'sell' page, if you transfer to the 'sell isotope' page, it will automatically sell Uranium 238. That's because the SB2 button corresponds to Uranium 238 in 'sell isotope' tab. So be careful!
*Caution3: if you do this, an error popup will constantly come up. I just enabled the 'never show this popup' checkbox and after that it just worked fine. But one side effect: the usual popup that came up after pressing the 'save' button no longer appeared... but its worth the sacrifice isn't it?
anyway, if you want to automatically sell other ores, all you have to do is type similar codes like:
setInterval(document.getElementById("SB3").onclick, 300);
setInterval(document.getElementById("SB4").onclick, 300);
... etc.
see that just changing the number after "SB" corresponds to the next ore(isotope) in the list.
Well, thanks for reading this much, and I hope other Mr.Mine users can be creative and do more through this technique.
You could use a packet capturing tool such as wireshark. With that figure out the format and data that the game sends to the server.
Once your know the structure you could write your script to intercept your game traffic, add the needed parameters and send requests on a timed basis. (This is all assuming it does encrypt its network traffic, in which case this may be a bit more difficult)
You may find some additional information with this search.
perhaps you can use http://www.sikuli.org/. i have successfully used this to do a fairly complicated automation routine for eve online.

Simulate browser and control programmatically

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.

python: open unfocused tab with webbrowser

I would like to open a new tab in my web browser using python's webbrowser. However, now my browser is brought to the top and I am directly moved to the opened tab. I haven't found any information about this in documentation, but maybe there is some hidden api. Can I open this tab in the possible most unobtrusive way, which means:
not bringing browser to the top if it's minimzed,
not moving me the opened tab (especially if I am at the moment working in other tab - my process is working in the background and it would be very annoying to have suddenly my work interrupted by a new tab)?
On WinXP, at least, it appears that this is not possible (from my tests with IE).
From what I can see, webbrowser is a fairly simple convenience module that creates (probably ) a subprocess-style call to the browser executable.
If you want that sort of granularity you'll have to see if your browser accepts command line arguments to that effect, or exposes that control in some other way.

Categories