I'm taking screenshots with selenium from a remote server. When the screenshots are taken from my local computer, everything works fine. But some of the screenshots from the remote server are coming with a dark black shadow over some elements.
here is how the screenshot looks like
In the black area must have some content. And after changing some color properties, we can see that the content is there actually. The weirdness in my opinion, is the fact that some elements are just fine. I already tried to increase the wait before taking the screenshot and the method used for(selenium has more than one method for taking screenshots).
self.driver.set_window_size(self.width, total_height)
timefrommoduletime.sleep(self.minimum_sleep_between_actions + 5)
self.driver.save_screenshot(path)
Related
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?
I have an extremely simple application for a Raspberry Pi. (It's an educational kiosk for a children's museum if anyone cares.) In python, I have an infinite loop in a thread reading a line from a serial port. Based on the input, I display one of 14 different jpg images. I am not putting all the code here, but it's a very bare-bones GDK application. I have an Arduino feeding the serial port the information to cycle through all the images for debug purposes. In response to the input, I do the following:
self.CurrentImage.set_from_file("image.jpg") # the name here is one of 14
Not to anyone's great surprise, this works. But as I let the Arduino hammer at the input, the screen would randomly show a white image and nothing again after. I checked the standard out window and the data was still coming and the images still being read. And when I say random I mean that at some point in the input-and-display process, it stops displaying. There are no errors being reported. Sometimes I might get 4-5 images in sequence before it dies, or I might make it through the list twice. It's simply not deterministic. My mind wandered to thinking maybe I'm not clearing first and having a memory leak. I made the following amendment:
self.CurrentImage.clear()
self.CurrentImage.set_from_file("image.jpg")
The problem persisted. I decided to scrap the method and go for something that didn't involve reloading images. At startup I created a separate GTK Image widget for each file. Then in response to the input data, I did this:
self.CurrentImage.hide()
self.CurrentImage = self.AlphaImage # or one of the other 13 Images I created
self.CurrentImage.show()
The nice thing about this method is that the image displays much faster. The first method had the screen briefly go white as the image was loaded. However, once again, after a random number of image switches, the window goes white. Diagnostic output shows that the loop is happily reading data and selecting images.
In the original version where I loaded images as needed, there was exactly one widget on the window. So it's not possible that another widget is covering it. The second version has an Image widget for each jpg file. If one is covering another, I should still at least see that image.
I'm good at thinking outside the box, but I admit that Linux is a weak area for me. Nothing is occurring to me to try to make this work. I'd whinge that I'm under time pressure here and children will be disappointed... but it was supposed to be done before Christmas and I only got the final art yesterday. That reminds me that there's one final note and the reason I thought my first method was failing: I created temporary graphics of my own that was one word of black text on a white background. Those images displayed without problem until the screensaver kicked in.
I'm open to any suggestion as to how to track this down and fix it.
Thanks to Sylvester, I figured this one out. The problem isn't how I was updating the images, it was where I was doing it. In the thread catching the serial input was not the place to do it. I reduced the thread to simply reading the line, then did the following:
GLib.idle_add( self.updateImage, lineInput )
then in the function updateImage I did the business logic of selecting the correct image and updating. Problem solved.
I use Bokeh to plot some interactive charts for my project, the Bokeh app runs on server. I like these charts can be plotted in full size on clients' browsers no matter what local resolution would be. Could someone give me a clue on how to get remote screen's max size?
I tried selenium, which asks user install drivers on local computer. It is not a good idea.
Also I tried python win32 API, which gets server's not remote computer's resolution.
Thanks
I don't know how to get the screen's size, but I have made my bokeh figures take up the full browser window (not necessarily full screen, but would be if the browser was full screen).
Instead of:
figure(plot_width = ... , plot_height = ... , ...)
I used:
figure(sizing_mode="stretch_both", ...)
("scale_both" is an alternative, which keeps the height/width ratio if you set those too).
Info from bokeh documentation.
There is a webpage which when loaded uses a random placement of forms / controls / google ads. However, the set is closed--from my tests there are at least three possible variations, with two very common and the third very rare.
I would like to be able to classify this webpage according to each variation. I tried analyzing the html source of each variation, but the html of all the variations is exactly the same, according to both Python string equals and the Python difflib. There doesn't seem to be any information specifying where to put the google ads or the controls.
For an example, consider a picture with two boxes, a red one (call it box A) and a blue one (call it box B). The boxes themselves never change position, but what takes their position does.
Now consider two possible variations, one of which is chosen everytime the webpage is loaded / opened.
Variation 1: Suppose 50% of the time, the google ad is positioned at box A (the red one) and the website control is thus placed at box B (the blue one).
Variation 2: Suppose also 50% of the time, the google ad is positioned at box B (the blue one) and the website control is thus placed at box A (the red one).
So if I load the webpage, how can I classify it based on its variation?
If the HTML is definitely the same every time, the variations are probably being done on the client side using javascript.
The answer depends on what you mean by "classify." If you just want to know, on any given load of the page, where the widgets are, you will probably have to use something like Selenium that actually opens the page in a browser and runs javascript, rather than just fetching the HTML source. Then you will need to use Selenium to eval some javascript that detects the widget locations. There is a selenium module for python that is fairly straightforward to use. Consider hooking it up to PhantomJS so you don't have to have a browser window up.
So I have a website which has a combo that I need to select an item from, now the problem is it's a bit untraditional and doesn't have option's as elements but instead it has divs.
So I need my program to click combo box then wait (the best way to do this I found is via implicitly_wait(3)# 3 seconds) and then click the box element I need. Firefox is doing a great job with it but PhantomJS seem to throw:
Selenium.common.exceptions.ElementNotVisibleException:
Message: 'Error Message => \'Element is not currently visible and may not be manipulated\'
I'm not sure what's the cause of it, but I suspect that PhantomJS fails to correctly wait via implicitly_wait for some reason and tries to select non-visible element.
Any idea how to approach this without forced thread sleep?
Yup, your issue sounds exactly something I've just fixed in a UI test that was starting to anoy me. Quite a complex one, that passed on all browsers, except my favorite PhantomJs (which is the fastest).
It was quite anoying, when in the debugger I could clearly see that even the parent element was set to visible. Only the prime faces component I needed to click for whatever reason (not CSS or active Styles) was not visible.
After looking at Phantom JS screenshot, I realized the window was quite tiny, and indeed the UI element was not visually visible.
You see now where I am geting at?
Phantom JS is a headless browser, it does not render you the window, but it does use a window, and the window does have a size.
The exception is quite unexpected, because the engine behind is the same as the one used for chrome and safari ... things should just work.
Well, and they did in the end.
Try to tune your driver factory like this:
WebDriver driver = new PhantomJSDriver();
driver.manage().window().setSize(new Dimension(800, 600));
return driver;
Good luck.