I am attempting to create Coded UI tests for my organization. I'm using Selenium IDE 2.9.1, the plugin for Firefox. I'm recording my steps using the plugin, and then exporting my test case as a "C# / NUnit / WebDriver" file. I then open this file in Visual Studio 2015.
My current issue is that I cannot get the FindElement function to select the proper field. I'm using the following to select the field, but it's not working properly:
driver.FindElement(By.Id("FIELDID")).SendKeys("TEXTTOINPUT");
When I debug, this step causes Firefox to focus on the URL bar at the top of the page and then causes a System.NullReference exception.
I have searched all over, and cannot find a solution that works for my problem. I'd appreciate any information you can provide.
Regards, JM
Can you inspect the page using FireBug? That will give you the actual name of the field you are trying to find in Selenium. My guess is that either the id isn't actually set or it is dynamically generated which would make it different than what you are using the FindElement(By.Id("FIELDID")).
We used
driver.SwitchTo().Frame(driver.FindElement(By.Id("tabRequests_frame0")));
...because the item we were selecting was in a frame.
Related
I'm writing Selenium tests in C# with Specflow and Nunit for a new project i'm working on and nothing inside the body can be selected anywhere at all
I can access body with
WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("body")));
but can not of the following work and throe element not found exceptions:
WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("halo-root")));
WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("halo-entry")));`
WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("halo-navigation-container")));
etc
error: no such element: Unable to locate element: {"method":"css selector","selector":"halo-root"}
There are no iframes
I have tried long waits to ensure its nothing asynchronous
the website is angular.js (I have tried some protractor approaches but nothing successfully)
I've also played around wit ElementIsVisible, ElementIsClickable etc
Ive tried different selectors (id, className, xpath etc)
All help appreciated
p.s cant share the entire SUT as it required vpn access.
First check your html. i think body tag must be present in iframe.
If it is present in iframe first switch to iframe then try any commands(wait or actions) on element.
The issue was when logging in through a portal (Jumpcloud) a new tab was opened (that I didn't notice) so the solution was just switch to that new window with _driver.SwitchTo().Window(_driver.WindowHandles[1])
Thanks for all the help though! :)
I am trying to automate a web application developed using angular JS through selenium webdriver(C#) and in that i am trying to click on a cell in a angular UI grid, i tried finding by css selector or xpath but it didn't help.
Css selector is generating dynamic ID - #\31 460691734316-0-uiGrid-00KQ-cell > div
Xpath is also dynamic //*[#id="1460691734316-0-uiGrid-00KQ-cell"]/div
and i tried using
driver.FindElements(By.CssSelector("*[id^='1460'][id$='cell']"));
but it didn't help
any help will be highly appreciated. I can send more details if needed
For my particular problem with the HTML page containing iframes and developed with AnglularJS the following trick saved me a lot of time: In the DOM I clearly saw that there is an iframe which wraps all the content. So following code supposed to work:
driver.switchTo().frame(0);
waitUntilVisibleByXPath("//h2[contains(text(), 'Creative chooser')]");
But it was not working and told me something like "Cannot switch to frame. Window was closed". Then I modified the code to:
driver.switchTo().defaultContent();
driver.switchTo().frame(0);
waitUntilVisibleByXPath("//h2[contains(text(), 'Creative chooser')]");
After this everything went smoothly. So evidently Angular was mangling something with iframes and just after loading the page when you expect that driver is focused on default content it was focused by some already removed by Angular frame. Hope this may help some of you.
What about trying to find the element with Selenium IDE which is a plugin of firefox ?
In the IDE, you can easily find the selector using selecting the element with GUI
Rather than identifying the element specifically by its ID, could you use the elements around it instead? Is this cell within a table and at a consistent position? Is there a parent element you could more consistently select and iterate through the children in your C# program to identify the appropriate cell you're looking for?
I have been using Selenium along side C# in Visual Studio 2013. I will make a call to:
driver.Navigate().GoToUrl("http://<insert webpage>");
...Which will open whichever WebDriver I choose to use.
From here, I will make calls to links/text boxes/menus as I need to.
However, I was wondering if there is a way to get the information from webpages without having to actually open a browser, and if so, could someone perhaps explain or link me to the right direction? It would save time and speed up a lot of my programs. I know applications can get information remotely without actually opening a browser, I just do not know how the process works or if Selenium alone will give that ability.
I appologize if this is wrong place to ask this question.
It is not clear whether or not you need to work with web page (like click on the links, or edit test), but here are two options:
You can use PhantomJS.It is headless browser and since there will be no UI execution may be faster. There is a selenium driver for it.
You can use Html Agility Pack to parse the page and WebClient to download the page. No selenium is required in that case. Html Agility Pack will allow you to make XPath queries, find objects by class name or ID. But: you won't be able to manipulate with DOM structure as you can do with real browser. It is just to parse and navigate over static html page.
I am using the code generator for Coded UI Test by recording the actions and I have a problem and a few questions:
Problem
The problem I am having is that I am trying to record a test. I go to a main page and click a link. The problem is that this specific link "crashes" Visual Studio. Whenever I click it using IE it stops working for a while, then after a few seconds the recorder prints this message: Last mouse action was not recorded.
This link works when I'm not recording, and the recording works with Chrome. But it does not when I'm recordgin with IE. I realised that there is something different about this link, it looks like this on the source:
...
...
While the other links have something inside the <a> tags. Is that the reason? Why does it work when not recording and it does not when recording?
[I am on a Windows 2008 with Visual Studio 2013]
Questions
How am I supposed to use these Coded UI Tests? One CodedUITest.cs for each functionality or several related tests in one file?
Is it possible to pass a browser as a parameter (i.e. IExplorer, Chrome) so a test can be run in that browser? I am able to run a test in with the same code in different browsers by:
...
BrowserWindow.CurrentBrowser = "Chrome";
UIMap.CheckMainPage();
...
What I am asking is if there is a way to run a test like CheckMainPage("Chrome") instead of writin a new method.
since codedui test methods cannot get parameters you have two options to cset the desired browser:
use Data Driven tests - this will multiple your test for each row in your data: https://msdn.microsoft.com/en-us/library/ee624082.aspx
read the values from a config file (so you could change the browser without changing the code)
to my knowledge the recorder only works with IE but the test can run on different browsers. (see attached link to MSDN)
https://msdn.microsoft.com/en-us/library/jj835758.aspx
as to why the recorder fails on that specific link - more information is needed - but perhaps the lack of any unique identifiers preventss the recorder from loaction and recognising the link (if possible add an Id attribute to the a tag and retry).
I wanted to make a small test site using the Metro UI framework (http://metroui.org.ua/)
So, I started up my newly installed Visual Studio 2013 and started a "new website". I added the neccesary css and js and made a very basic masterpage and default.aspx. But here comes the problem: the css does get loaded, but it doesn't get applied. Not in FireFox, not in IE, not in Chrome and not in the "Page Inspector".
It's quite weird, because in my previous VS2012 this same workflow for testing and experimenting with a framework just worked. I really can't find the problem. Maybe it has to do with my new Windows 8.1, my new Visual Basic 2013, maybe an programming error (although that would be very unlikely, since I checked everything).
I also tried installing the framework using NuGet instead of manually adding it. Same result: it does load, but it doesn't get applied.
Anyone knows what's happening here?
Thanks in advance!
According to MetroUI you have to follow 5 simple steps
Create page with HTML5 DOCTYPE
2.Include metro-bootstrap.css
Include metro.min.js (jquery.js required)
Create main container with class .metro
Use markup, as described in the pages of this site
In your posted images I can't find a container with class .metro . I'd really check the sample code from the posted page.
In case I misunderstood anything please let me know!