Is there a way to take a screenshot of JUST the browser window using Selenium RC? I am able to use the captureEntirePageScreenshot and the captureScreenshot methods but neither are what I want... My goal is to create screenshots, of a certain size, as the Selenium script runs and then be able to include those screenshots in a document. I know how to set the size of the browser window... so if there is a way to take a screenshot of ONLY the browser window, I'd have the images I need.
Related
Below I describe the issue I need help with.
Description
I wan't to simple copy content from URL: https://www.di.se/bors/large-cap/ to my Windows clipboard. I scroll down a bit on webpage (to get all content) and mark all before copy.
I want to this in selenium headless mode.
Problem
When I scroll down a little on the page and mark all and then copy the content, the clipboard does not contain the content I copied in headless mode in selenium. Important to know that this working as expected in normal selenium mode.
I have tried with three different browsers: Chrome, Edge and with Firefox. I have also tried with different ways to make the nessecary key strokes (sendKey, Actions and with the Robot class). See code example of the different ways below. Regardles what I'm doing the content is never copied to the clipboard.
Examples:
((JavascriptExecutor) driver).executeScript("scroll(0,400)");
driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "c"));
Actions builder = new Actions(driver);
Action selectAll=builder.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build();
Action copy=builder.keyDown(Keys.CONTROL).sendKeys("c").keyUp(Keys.CONTROL).build();
selectAll.perform();
copy.perform();
iRobot.keyPress(KeyEvent.VK_CONTROL);
iRobot.keyPress(KeyEvent.VK_A);
iRobot.keyRelease(KeyEvent.VK_A);
iRobot.keyRelease(KeyEvent.VK_CONTROL);
iRobot.keyPress(KeyEvent.VK_CONTROL);
iRobot.keyPress(KeyEvent.VK_C);
iRobot.keyRelease(KeyEvent.VK_C);
iRobot.keyRelease(KeyEvent.VK_CONTROL);
Question
Is there a way to copy the content to clipboard or can some workaround help?
From what I can find, it seems there is no way to access the clipboard in headless mode. I can't find anything definitive but this is as close as I can get to proof that it can't be done: https://groups.google.com/g/selenium-users/c/-nxTX4eTbwA/m/wQY_HlZQBAAJ
currently during debug of test cases selenium is opening a new firefox window, in whatever desktop screen it chooses. I want to be able to have selenium attach to the existing window (and not close the window when the test is over.)
I see this in the selenium documentation
webdriver.firefox.useExisting Never use in production Use a running instance of firefox if one is present
but I do not see how to set it from rails/rspec/capybara
I have looked at the related SO answers, and they are more to do with attaching to a running test. I just want to control where the window is, and be able have the window open with the developer console, so we can see what is going on, and finally have the window stay open at the end of the test
Depends on the issue 2163 it was a feature of Selenium 1 and not implemented to Selenium 2 but still stays in documentation. Check this issue.
I'm trying to make automated tests for a site, using Selenium IDE (not Selenium Server, RC, 2.0, and WebDriver).
I want to be logged in with user 1 in Firefox window 1 and open a Firefox private window to sign in with user 2. I need this because the website I want to test doesn't allow multiple users signed in in the same browser at the same time.
So:
1) Is there a way to open a private/incognito window?
2) How do I then switch back to the main window?
Here's how switching between simple windows looks like:
http://i.stack.imgur.com/P5bbt.png
In the attached image you can see how I solved the problem:
It works fine with Firefox version 42.0 (and earlier versions). With Firefox 43 I have some problems because "openWindow screen2" does not overwrite my window I open with javascript but opens an own window. I'm looking for a solution for this issue.
As far as I'm aware this isn't something that Selenium IDE can do. The best solution I can think of would be to use something like Autohotkey and combine the it with Selenium.
With AHK you can set a script to mimic the keyboard command to open a private window (ctrl+shift+p). When I've used it with selenium in the past I've set the AHK script to start when it detects a certain window title, and then had selenium call a javascript function from the user-extensions to amend the title of the page you're on to the title which will trigger the function when you need the AHK script to run. (Best not to use the default one, otherwise you could end up with countless private windows if it hits that page multiple times).
Try this,
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.private.browsing.autostart",true);
I am using the Selenium IDE extension for testing webpages in FireFox and I was able to find out how to perform almost every command that I need to automate testing for my webpage.
Unfortunately I was not able to find out how to do this through the list of commands that you can manually enter into the queue of Selenium IDE.
I was wondering if anyone knew how to do this in the Firefox extension. Thanks!
You can use dragAndDropToObject command which locates the target element and drags it to the centre of the destination element.
dragAndDropToObject
target: locator of the element to drag
value: locator of the destination element
There is also a dragAndDrop command which drags the element by specified amount of pixels and drop it.
For one thing, you might want to use Selenium Builder instead of Selenium IDE. Also, there are some things that Builder or IDE cannot record, such as iFrame interactions, certain AJAX actions, and also drag and drops. For those, you need to code them by hand afterwards and get them working.
I am using selenium IDE 1.10.0. I am trying to check presence of image in product categories. what command should i use to verify image?
Open selenium IDE in FF browser
Right click on the image, then you see assertelementpresent command, if you do not see this command then hover over Show all available command and select assertelementpresent
Check image
try using
assertElementPresent //img
The second is xpath relative to image
Best way how to find out for yourself:
Open Selenium IDE addon
Right click the element you want to check
Hover Show all available commands
Try to find most suitable command
use that command and see what happens
There are 3 ways of doing that depending on your task (why you need this image):
1) you may wait for the image to perform some actions (e.g. wait for the button to click it): waitForElementPresent(locator). It uses timeout set in your Selenium IDE.
So when element appears, your script will execute next line. If it does not appear - this case should be processed somehow (e.g. using verify - see item 2)
2) if you need to know if image is there - you may use verifyElementPresent(locator) - it returns true or false (and you may store this value). If image is not present - test will continue running (this is important!)
3) if this image is critical - use what was suggested here already: assertElementPresent(locator) - if image is not there test will stop.
P.s. I hope you know what locator means. If not - find samples, it is easy