In my app, when you click on some links, they open the url in a new tab. I'm having trouble trying to access the new tab.
I've tried using send_keys but haven't been able to get that to work. I'm using classic-watir (1.9.0), not watir-webdriver. Unfortunately, whenever I try to search on this, I get many results referencing watir-webdriver but none referencing classic watir.
I know at some point I should upgrade to watir-webdriver, but at the moment, I really don't have the time to upgrade all my tests.
Attaching to tabs is the same as attaching to windows.
You can attach to the new tab:
ie2 = Watir::IE.attach(:title, 'new_windows_title')
ie2.close #close the new tab
Or can use the window or windows method (note that this will work in both watir-classic and watir-webdriver):
#Close the last opened tab
ie.windows.last.use do
ie.close
end
#Close a specific tab
ie.window(:title => 'new_windows_title').use do
ie.close
end
Related
I have a website (private, sorry) that I'm trying to log into automatically but the login page has no source code available so am unable to assign/find specific elements.
The cursor is blinking on the Username input field, so trying somehow to start typing then tab to password field and then enter.
I've tried the following three different methods, neither fills in any text.
ActionChains:
actions = ActionChains(driver)
actions.send_keys("*username*")
actions.perform()
Passing info to the url itself:
driver.get("https://username:password#my_website.com")
By active element:
active_ele = driver.switch_to.active_element
active_ele.send_keys("test")
I'm guessing your target page is protected by Basic Authentication, and what you're calling the "login page" is not an actual "page", but rather the browser's Basic Authentication dialog box. This "pop-up box" is not an actual page element, so you can't manipulate it with Selenium's page-element API.
In my own Selenium code, with current Chrome (version 90), the "https://username:password#my_website.com" URL does actually work to open the target page. However, it doesn't "fill in any text" like you said; it just directly opens the protected page. Also, a "https://username:password#my_website.com" URL doesn't work in the browser address bar itself; it only works in the Selenium API. Also, my tests are in C#; FAIK the "https://username:password#my_website.com" technique might not work in Python.
Note, Chrome removed the "https://username:password#my_website.com" feature for years, but then they brought it back, sometime before November 2019, when I discovered it; but they only brought it back for the Selenium API, not for the browser address bar.
I have three different Hyperlinks on a web page
Planning.
Solutions.
Contact Us.
I want to open them in separate browser tab one by one using codedUI.
i have written the above code to obtain the list of Hyperlink
HtmlControl Hyperlink = new HtmlControl(browser);
Hyperlink.SearchProperties.Add(HtmlControl.PropertyNames.ControlType,"Hyperlink");
UITestControlCollection controls = Hyperlink.FindMatchingControls();
foreach(UITestControl control in controls)
{
if (control is HtmlHyperlink)
{
HtmlHyperlink link = (HtmlHyperlink)control;
if(link.InnerText=="Planning"|| link.InnerText== "Solutions")
{
//separate Tab logic goes here
}
}
}
I need the help related to opening a hyperlink in new browser tab. Is it possible in CodedUI ?
By default if you click the mouse middle button (or click the scroll wheel), it opens a link in new tab. I would modify your code as below in this case,
if(link.InnerText=="Planning"|| link.InnerText== "Solutions")
{
//Open Link in New tab, by clicking middle button
Mouse.Click(link, MouseButtons.Middle);
}
You can do this a couple different ways. I would use #Prageeth-Saravan 's approach first to see if it works because it's easier and actually tests your UI. You could also:
Get the URL from the found link control
Send the "New tab" keyboard shortcut
Reinstantiate your browser window object to be sure it's pointing to the new tab
Navigate to that URL
The reason why I bolded step 3 is regardless of approach, if you intend to assert or interact with anything in a new tab you're going to have to remember that the CodedUI software will still be "Looking" at the old tab until you reinitialize it.
I am using then new NavigationBar control to control a series of applications. Using the basicLeafNode I have this in the href:
var prefix:String = "";
if (#ClientType() == "Web")
{prefix = "https:xxx/"}
else
{prefix = "notes:xxx"}
url = prefix + "path/databsase.nsf?OpenXpage";
url
This works fine except in XPiNC I want the link to replace the tab, not open a new window. How can I do this?
===================================================
To clarify, I want the target to replace the current tab, not open a new one. While primarily a web app, the users will access it from XPiNC.
In the onClick event of the NavigationBar I have this in CSJS:
window.open('notes://<server>/common/db.nsf/xpHome.xsp?OpenXpage','_self')
Just trying to get this to replace the current tab in XPiNC. It opens a new tab. Shouldn't it replace this tab?
Brian - in XPiNC the URL is /xsp/path/database.nsf if you are going to do it manually you have to adjust for the XPiNC environment.
In the XSP Properties there is a setting on the General tab for Window behavior for the Notes client.
I use watir in RadRails IDE. I need to attach a new window by it's title, but in my web application there could be an error, the title is missed. So I can't use the code:
ie3=Watir::IE.attach(:title, 'Mt Title').
The page is loaded and I can perform some actions there. Is there way to focus on that window not using page title? Or how can I define page title?
Maybe there is a possibility of choosing a window by name or some other attribute and if I do not know the exact name then can I define it or define names of all opened windows?
If there is only one IE window this would work:
browser = Watir::Browser.attach(:title, //)
If you want to check if there is a page with a title, try something like this:
begin
browser = Watir::Browser.attach(:title, "teh codez")
rescue Watir::Exception::NoMatchingWindowFoundException
puts "could not find browser"
end
I am new to Watir, and am working on developing a testing tool for my work.
I have run into a problem that I cannot seem to solve, even after checking several sites.
The javascript window creation is below: (the window created holds a pdf in a window, so the only "buttons" are the minimize, maximize, close)
<a id="LogIn_HyperLink2" class="ms-WPTitle" onclick="javascript:var win = new Window({className: 'spread', title: 'Security Statement', top:0, left:1, width:750, height:365, url:'--redacted--/security.pdf', showEffectOptions: {duration:1.0}}); win.setConstraint(true, {left:10, right:20}); win.showCenter(); return false;" href="--redacted--/security.pdf" style="color:#6699cc; font-weight:bold;">Security Statement</a><br>
I have tried using both
puts browser.modal_dialog(:title, "Security Statement").exists?
puts browser.javascript_dialog.exists?
both have returned 'false'
What approach should I be taking to attach to this new window, or more directly: How can I close this new window?
You can see the page at this link (IE only)
If the window holds a PDF file it's a browser window, not a modal javascript popup (alert, confirm, prompt)
It's defined to start without all the normal menus etc active, but it's still a browser window. You can attach to it as described in the Watir Wiki section about new browser windows, using the url or the title since you know both of those (given the HTML you showed us).
If you are using Watir-Webdriver use it's window switching commands. Right now the watirspec for that is your best reference to the methods supported and how they work.
EDIT
Thanks for the link. While the above would be true for a new browser window, that's not what you are faced with. What you have there is all inside the browser HTML, created in the DOM on the fly with javascript. It's all standard HTML elements, easily interacted with once you know what's going on (this is actually IMHO easier to deal with than a popup or separate window)
Use the IE developer tools, after you click the link that makes that 'window' appear, click the icon in the toolbar of the dev tools to refresh the DOM in the dev tools and you will be able to see that.
The outermost container appears to be a div of class 'dialog', which is unique in the DOM at that point.
The window controls are three divs under that one, with classes 'spread_close', 'spread_minimize', 'spread_maximize'. There are three tables that hold the graphic elements for the top, sides, and bottom of the 'window' but there is ZERO actual content there, it's just a visual windowframe.
There is also an iframe that superimposes that window, which is I think were the content would be (I can't get it to load, maybe because I'm not authorized for it or something)
If you just want to close the window, try this:
browser.div(:class => 'spread_close').click
Since this is coming into existing due to a bunch of client side JS code you may need to use something like the 'when_present' method after clicking the link before you first start to interact with it. eg if all you want to do is click the link to open it, and then close it, you'd do something like this
browser.link(:text => 'Security Statement').click
browser.div(:class => 'spread_close').when_present.click