java - WebDriver open new tab -
I have detected the Web and WebDriver API. I do not see any way to open new tabs using WebDriver / Selenium 2.0.
Can someone confirm if I am right?
Thank you, Chris. PS: The current option I see is either loading a different URL in the same window or open a new window.
There is a completely cross browser approach to using a WebDrive, which says that you Still can not be lazy. First of all, you need to use a WebDrive to tag the page that opens the tab you want. Here's how I can do it (Note: Driver is a Web driver instance):
/ ** * executes a script on an element * @ Note actually then The only thing that should be used when the web driver is sucking * functionality natively * @ the ultimate script * to execute the script * @ The goal of the ultimate element script, Logic [0] * / Public Zero Trigger (string script, Web allem Print is referred to as elements) ((JavaScript Akskshk) driver) KexecuteScript (script elements); } / ** executes a script * @ Note should be used only when the web driver * is exposed to the functionality * Normally exposed * to execute * the absolute script * / public object trigger (string script) Script {return ((javascript exciter) driver) .executeScript (script); } / ** * Opens a new tab for the given URL * @ Param URL * URL * @through JavaScript Exception. * Unable to open tab * / Public Zero Openband (string url) {string script = "var d = document, a = D.createElement ('a'); a.target = '_ blank'; a.href = '% S '; a.innerHTML ='. '; D.body.appendChild (a); Return "; Object element = trigger (string format (script, url)); If (for example Web Element) {WebElement anchor = (WebElement) element; Anchor.click (); Trigger ("var a = logic [0]; a.parentNode.removeChild (a);", anchor); } And {new JavaScript exception (element, "unable to open tab", 1); }}
Next, you must tell the web driver to switch your current window handle to a new tab. Here's how I do:
/ ** * Switches non-current window * / Public zero switch window () throws NoSuchWindowException, NoSuchWindowException {Set & lt; String & gt; Handle = driver GetWindowHandles (); String current = driver. Gatewandhandsley (); Handles.remove (current); String newTab = handle Nitter (). Next (); Locator.window (newtab); }
Next, you can interact with the elements in the new page context by using the same WebDevice instance. Once you do that with the tab, you can always return to the back window window using the same mechanism in the switch window. I will leave it as an exercise for you.
Comments
Post a Comment