I'm using selenium testng format for testing my UI. I want to shift my focus from my main window to another window, where i click on a link before the page on my main window has finished loading.
Clicking an Element on page load is even possible on webdriver; By default, webdriver wait for the entire page to load and then picks the element. The links and texts are visible but they are not clickable; However, it works well on Selenium IDE picking elements on page load.
I hope the below Firefox profile will help you to do the same for switching windows.
Webdriver make use of the FirefoxProfile to avoid such risks; It's applicable only for Firefox browser.
FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("webdriver.load.strategy", "unstable");
driver = new FirefoxDriver(fp);
Well i found a way around my problem. Instead of trying to shift the focus from one page to another i just ran the tests parallel to each other.
For more info you can check this link: (http://blog.wedoqa.com/2013/07/how-to-run-parallel-tests-with-selenium-webdriver-and-testng-2/)
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
I have selenium.support version 3.141.0, chrome driver version 2.43.0 and Google Chrome version 71.0.3578.98 and Selenium.ChromeDriver.dll 2.43.0.
when i click on a certain button a new window should be open. i click on the button and if i use any action on the browser for example new WebDriverWait(_driver, TimeSpan.FromSeconds(60)).Until(IsPageLoaded); the window stop to load and stay blank data. why can't i get the browser to load it's content?
Edit: when the new window opens i change the the driver to the latest windowHandel and use the webDriverWait from above to wait which result in a blank data window, but if i use thread.sleep after changing the windowHandel the window load its content
You can try with a explicit wait for a element to be visible on the new window. That would ensure it waits for the contents to load up
I have a scenario where i need to right click on a link, when context menu appears i need to click on option "Open link in incognito window".
When i try to achieve this by below code snippet i could see a context menu appears but instead of launching the link in new window the link gets launched in same window.
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.google.com/");
Actions action = new Actions(driver);
WebElement ele = driver.findElement(By.linkText("About"));
action.contextClick(ele).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform();
any suggestions how to make this happen?
There may be a keyboard shortcut for opening a link in an incognito window but I was unable to find one but I didn't look for long. You may have better luck.
Another method would be to grab the URL of the link you want to click, open an incognito window using the keyboard shortcut (CTRL+SHIFT+N), and then navigating to the URL. It's not ideal but I don't know of another way to do this.
Is there some reason you can't just start your script in an incognito window and proceed from there?
This context menu is not a part of html page, but this is a menu coming from Chrome (a desktop application)
Selenium/WebDriver does not have the capability to automate the desktop applications, you can use AutoIt or similar software to do it
But all what you need is just to open a new browser session (incognito window is nothing but a new, independent browser session).
To simulate this behaviour using WebDriver just open a new Chrome driver:
WebDriver drv1 = new ChromeDriver();
drv1.get("https://www.google.pl");
drv1.findElement(By.name("q")).sendKeys("About");
........
........
// This will open a new browser window with a new, independent browser session
WebDriver drv2 = new ChromeDriver();
drv2.get("https://www.google.pl");
drv2.findElement(By.name("q")).sendKeys("Hello");
........
........
drv1.do-Something-in-session-1
.....
drv2.do-Something-other-in-session-2
....
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.
js gets downloaded to browser cache.
js contains functionA that constructs the url and calls the window.Open to open the url.
i call the functionA to open the window.
selenium doesnt detect the window at all. i did getAllWindowTitles and getAllWindowNames, etc. But do not see window at all.
by the way the reason i had to this is because when i click on button that has an onclick='calltofunction()', the window is not detected either.
it would be better actually if i can force selenium to see the open window after i click the button.
Thanks!
The straight forward answer that I can think of right now is to move on to Selenium 2.31.0, which has an updated support for WebDriver, and can be used in parallel to Selenium.
Then, it is easy to do ALT+TAB (for Windows, or CTRL+TAB for tabs), and WebDriver picks up the new tab/window and reads off of it.