Selenium Chromedriver control issue - selenium

I have started using chrome for selenium and its working fine but when I open a new tab the control goes back to the main tab and executes the script there instead of the new tab. can someone help me how to tackle this issue.

try this
ArrayList<String> tabs2 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs2.get(tabs2.size()-1));
//Then do something

# Open the link in a new tab by sending key strokes on the element
# Use: Keys.CONTROL + Keys.SHIFT + Keys.RETURN to open tab on top of the stack
url.send_keys(Keys.CONTROL + Keys.RETURN)
# Save the window opener (current window)
main_window = browser.current_window_handle
# Switch tab to the new tab
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
# Put focus on current window which will
browser.switch_to_window(browser.window_handles[1])
# do whatever you have to do on this page

Related

open a link in new tab in selenium

I am trying to open a link in new tab.
Trial1
Actions action = new Actions(Driver).KeyDown(Keys.Control).KeyDown(Keys.Shift).Click(FindElement(xxx).KeyUp(Keys.Control).KeyUp(Keys.Shift);
action.Build().Perform();
This code opens the link in new tab at the same time opens another blank window
Trial2 - right click the link and choose the first option "open link new tab"
action.ContextClick(FindElement(xxx).SendKeys(Keys.ArrowDown).SendKeys(Keys.Enter).Build().Perform();
This opens the link in new window instead of new tab
So what you need to do is first open a new tab using JS executor:
((JavascriptExecutor)driver).executeScript("window.open()");
or
((JavascriptExecutor)driver).executeScript("window.open('the new link here', '_blank')");
If you did not use the secon method continue with the following: switch to the new window and navigate to the link
driver.switchTo().window(here the window handle);
driver.get("here is the link");

Selenium Webdriver Actions are not working with context menu (right click)

I am trying to use Selenium Webdriver to right click on a page, and navigate the context menu. This script should open a right click menu, and navigate Up 2 options, then select with the Return key...
driver.Navigate().GoToUrl("http://www.google.com");
//Google search bar
IWebElement tb = driver.FindElement(By.Id("lst-ib"));
Actions action = new Actions(driver);
//Right Clicks outside of the search bar.
action.MoveToElement(tb, -5, -5).ContextClick().Perform();
action.SendKeys(Keys.Up).SendKeys(Keys.Up).SendKeys(Keys.Return).Perform();
The right click executes as it should (outside of the search bar), but after that, there is no evidence of the Up arrow being pressed, and nothing is selected with the Return key. The menu options should highlight as they scroll through.
I am using the latest version of ChromeDriver 2.30, and Chrome 59.0.3071.109
If your application only runs on Windows, you may use System.Windows.Forms.SendKey.
action.MoveToElement(tb, -5, -5).ContextClick().Perform();
System.Windows.Forms.SendKeys.SendWait("{UP}");
System.Windows.Forms.SendKeys.SendWait("{UP}");
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
If it is user designed context menu . The context menu itself would be having the locator
`WebElement element =driver.findElement(By.xpath("your xpath"));
Actions action = new Actions(driver);
action.contextClick(selectedCell).build().perform();
WebElement copyContext = driver.findElement(By.xpath("xpath of the right context column"));
if (copyContext .isEnabled())
{
copyContext .click();
log.info("Right context menu COPY CONTENT clicked.");
}
`
This chromedriver bug has been unattended since 2015.
I resorted to PyAutoGui for controlling dialog boxes.
http://pyautogui.readthedocs.org/

Close download bar

I am using Java and Selenium to write a test. Somewhere in my test, I download a file but then need to click on a button under the download bar which appears at the bottom of the chrome browser page. I search a lot but the only solution was here which is not my case as I don't have a scroll.
I also use:
action.sendKeys(Keys.CONTROL+ "j").build().perform();
action.keyUp(Keys.CONTROL).build().perform();
Thread.sleep(500);
ArrayList<String> tabs2 = new ArrayList<String> (driverChrome.getWindowHandles());
driverChrome.switchTo().window(tabs2.get(1));
Thread.sleep(500);
driverChrome.close();
driverChrome.switchTo().window(tabs2.get(0));
Thread.sleep(500);
but it doesn't open the download page.
Anyway that I can close the download bar?
This method did not work for me either, but I developed a workaround. I do any download test in a new window, then close the download window, the original window does not have the download bar. It must be a new window, if you do a new tab it will transfer over, to get this I use JavaScript. Switch to the new window, run download test and then switch to the original window when done.
string javascript = $"$(window.open('', '_blank', 'location=yes'))";
((IJavaScriptExecutor)Driver).ExecuteScript(javascript); //create new window
Driver.SwitchTo().Window(Driver.WindowHandles.Last())); //switch to new window
//do download test here
Driver.Close(); //close created window
Driver.SwitchTo().Window(Driver.WindowHandles.First()); //back to original window with no download bar

Unable to operate the prompts of spot fire using selenium webdriver

If anybody has tested spot fire web applications using selenium webdriver please help me. Spot fire uses prompts as popups. And am unable to locate the prompts buttons to click.
Steps i followed:
Save the current window handle.
Get the next prompt window
handle by traversing through iterator(While Loop).
Find the element on new window and click it. But when i printed current
window handle and new window handle are same.
Below is my code
String parentWindowHandler = driver.getWindowHandle();//Stored parent window
String subWindowHandler = null;
Set<String> handles = driver.getWindowHandles();
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler);
(....My click functions)
I have pasted the fire bug element track below for "OK" Button on prompts.
Next
I have tried to take control using "class" but its throwing exception saying it cant take common/general class.
Please suggest me how to proceed to click a OK button on spot fire prompts.
I forgot to inform.My Prompt contains a "scroll bar" and "Next" button and "Cancel" Button. I need to choose items from scroll bar and press next or cancel button.

Adding a new tab in a web brower supplied with VFP that uses the IE control

I am using a class supplied with VFP that uses the IE7 control _webview to open up a web browser and it does not have a function to add a new tab withen the browser , if I am clicking on link in a current page it will open it in IE , is there a way that the new page should open up on the foxpro browser ,
and How can I add a new tab in the browser for a new search
also is there a class that will open up a web browser in foxpro based on a more updated internet broweser
There is no tab in the control. you need to create new tabs in response of the NewWindow2 event from the webbrowser control, put a new webbrowser control on the tab, then tell the event that the new webbrowser control should be used to display the new window. Your event handler looks like this:
LPARAMETERS ppdisp, cancel
*creating new tab
newTab.ADDOBJECT("Olecontrol1", "OLEControl", "shell.explorer.2")
With newTab
.olecontrol1.Top = 0
.olecontrol1.Width = .Width
.olecontrol1.Left = 0
.olecontrol1.Height = .Height
.olecontrol1.visible = .T.
.olecontrol1.RegisterAsBrowser = .T.
.Visible = .T.
Endwith
ppDisp = newTab.olecontrol1.Object
By default the webbrowser control operates in IE7 mode. To opt-in to a new version, add a FEATURE_BROWSER_EMULATION registry key in your program's installer.