Duplicate elements in DOM when running Selenium browser tests - c#

This is a really weird one which I've never seen before and it's difficult to google.
We have a single page app which has internal tabs (not Chrome tabs, pure html simulated tabs in the app). We have end to end Selenium C# tests which run fine when using a single tab. We created some test which run with two html tabs open, and they failed. They failed because a modal with a Open button in it was duplicated & when the test went to click it, it clicked the original not the duplicated and threw an error. There should only ever be one instance of the modal and its components, in fact when you run it as a normal user thats exactly what happens. Here's the scenarios:
Running locally, as normal browser session, two application tabs open, open the modal dialog, one instance of the Open button in the DOM.
Running locally, debug run Selenium C# Visual Studio, two application tabs, open the modal dialog, two instances of the same open button in the DOM, test fails as code is looking for the 'first' one and error is 'another element will get the click'.
This is an Angular 4 SPA project - never seen anything like this before. There are elements in the DOM being duplicated depending on the browser mode. Has anyone else seen this?
Not sure if this is a problem with our app - which case why does it not do this when we run as a normal user? Or if its a problem with how we are launching Chrome from the test suite - we're not specifying any Chrome options when new'ing up a ChromeDriver instance.

'another element will get the click' doesn't mean that there is another element for the specified selector. It usually means that there is another element ON TOP of it (hiding it). I would recommend you creating screenshot right before and after the click and manually inspect if the element is indeed visible at that moment.
Also check if the element you are selecting is not by accident 0,0 size, and when a user clicks, click is received by a child or something like that

Related

C# Selenium how to interact with chrome extension

I have successfully loaded my chrome profile with selenium that has pre-installed extensions.
The extension in question is called Private Internet Access, but i have tried others and cannot communicate with them
I am trying to figure out how i can open the extension below and enter username&password and click login button. I have tried finding the elements in by id and class but it doesnt find them. Can someone point me down the right line for this. Thanks
I've not had the ability to try this - however I've done a lot of work with Selenium and I've created my own chrome extension.
That extension popup in the top right actually a different web page. You won't be able to interact with it due to how it's presented, but you can navigate to it.
Try this:
Open up your extension, right click anywhere and select Inspect. This will open up devtools for the popup.
In devtools, go to the console and type document.url. This will give you the URL of that popup page. (you'll also see it at the top of the title bar)
That gibberish-looking bit in the middle doesn't change - it's your chrome extension identifier. From when I created my extension and 18 months worth of updates (including migrating from chrome extension manifest v2 to v3) it has not changed for me. I think you'll be safe to use it.
Go to that URL to make sure it works. In my case it's chrome-extension://ojhcleddagaoaplflbafhpekcciikdop/popup.html
You'll notice you'll lose some of the page styling compared to the popup. When you design the popup you give it fixed dimensions - when you open it as a normal webpage, you lose that and everything gets stretched.
Finally - for your automation - put that chrome-extension:\\ url as the first step in your selenium script and do your sign in. Then, carry on with the rest of your test.

Design View Not Working in Visual Studio 2013

I've been creating a new webforms website in c# and been working exclusively in source view until yesterday when I wanted to create a method for a button click for the only dynamic part of the site and I was confronted with this:
I've never seen this before! Every page is the same and it reoccurs on another machine with VS 2013 The site renders fine and publishes without issue. Other websites work fine, so it's got to be this project.
I don't know if this is a separate issue or is part of the same problem, but I managed to link up the button to a method using Resharper, but data from textboxes are not passing to the method, which again I've never had before.
It's a 30 page bootstrap site (replacing an old site) that I've nearly finished! Am I screwed??
Any help would be appreciated.
EDIT:
It's not that I'm worried about seeing the page render in design view. I never use it. I just want to be able create the button click event method. At the moment the button click is just reloading the page and not passing form data to the method.
This happens due to improper termination of the Visual Studio processes due to which the files get corrupted for which you might need to use system restore or re-installation of the product. Still assuming that its caused due to some setting mismatch we can perform the following steps.
1.right click on an html file listed in Solution Explorer
2.in dialog box that opens click on: Open With...
3.click on: HTML (Web Forms) Editor, AND on the right pane click on Set it As Default
after this action all html files that you open have options: Design...Split...Source.
Reference : http://social.msdn.microsoft.com/Forums/vstudio/en-US/25d6c666-6216-4fa8-992b-f9bb088dfc7d/visual-studio-2013-missing-design-source-and-split-buttons

Get a specific tab in MSIE 9

I am using Watin 2.1 to try to test file download and file open functionality for a website.
This worked well in Internet Explorer 8, but since Internet Explorer 9 there is a yellow-white download bar at the bottom of the view instead of a popup dialog window.
I found this answer:
https://stackoverflow.com/a/8532222/246622, which solves that problem, as long as the browser tab that I am interested in is on top.
If there are other tabs that are on top, it cannot not find the download bar.
The problem here is that these tests will open other tabs on top of the tab with the download bar, before the download starts.
So, how do I access the correct tab, or how do I switch the top/visible tab in internet explorer, or how do I get those other pages to open in other windows instead of in tabs in the same window, or how do I close those other tabs from my test application?
Here is the relevant piece of code:
Window windowMain = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(browser.hWnd, 5/*GW_CHILD*/)); // This gets the topmost browser tab.
System.Windows.Automation.TreeWalker trw = new System.Windows.Automation.TreeWalker(System.Windows.Automation.Condition.TrueCondition);
mainWindow = trw.GetParent(System.Windows.Automation.AutomationElement.FromHandle(browser.hWnd));
windowDialog = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(windowMain.Hwnd, 5));
I tried this:
var lowerWindow = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(aBrowserTab.Hwnd, 2/*GW_HWNDNEXT*/)); // This gets a next lower window.
I was then planning on identifying the correct tab using a regex with the title:
titleRegex.IsMatch(windowMain.ToplevelWindow.Title)
but this gets a lower window instead of a lower tab in the same window.
I had a similar problem and after investigations similar to what you are trying I decided to try alternative routes. Also note that even if you do get it right like this, you'll have a lot of work to port your tests on other browsers and IE 10 is coming out fast.
Do you really need to download the file from the browser? How about - read the URL that triggers the download and then do a WebRequest on that URL to retrieve your file?
Look at using Coded UI - not the recorded tests but the generated ones. They are able to automate clicking on window apps as well as within the browser. Also note that development does seem to have stopped on waitn so it might make sense to move to something more reliable.

Window not found exception comes when switchTO().Window("windowname") is used

I am using Selenium webdriver for Automation in c#, In the web page I have a button,when that is click new IE pop up gets opened, now i want the webdriver to continue the clicks for that new IE window pop up;
[Note:- The Child IE pop up is complete new .aspx page the window name of that i Checked by doing View Page source after right click and that is window.open("../Reports/MidWayReport.aspx");]
after a button click i tried following code.
webDriver.SwithTO().Window("windowname");
but that is generating "No window found exception.
It's likely a timing issue - try waiting a couple of seconds before trying to switch to the window.
It's either a timing issue or you haven't named the window. I think by default all new windows that aren't specifically named get the name _Blank. That may have changed as it's been years since I've looked at that across multiple browsers. However, there is an easier solution just name the window.
window.open("../Reports/MidWayReport.aspx", "MyWindowName");
Then you can do something like this
webDriver.SwitchTo().Window("MyWindowName");
This used to be set by a link that opened a popup like this
Open Window
However since you are doing this via javascript I provided the way to do that first. Here is a link to explain: http://www.infimum.dk/HTML/JSwindows.html

How to pop a web browser from Silverlight OOB?

I want to pop a web browser popup window, with a given url, from Silverlight.
When running within the browser I use HtmlPage.Window.Invoke() to run a javascript and its window.open() in the host browser. Works fine.
But when I run out-of-browser (OOB) this technique obviously doesn't work. So, what to do?
Silverlight 4 has this new WebBrowser control for use when running OOB. It works fine, but I have only been able to run it in a child window within the silverlight application boundaries.
Then there is this hyperlink trick. Also works, but it creates a new tab in the current browser-instance. Not exactly what I want either.
Anything I have missed?
(Alternatively; is there a a way to make the hyperlink pop the url in the same browserinstance and tab every time? instead of creating new tabs.)
Bit of a long post this. Sorry about that and thank you for your patience.
The link you posted to creating a derived HyperlinkButton is the only one I know of. Maybe play around with different TargetName values to see which one works like you want? "_blank", "_new", etc... - one of them may be what you want.
The trouble is that different browsers (when set as the default browser) may do different things, so be sure to try this with IE, Firefox, on a Mac, ...

Categories

Resources