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! :)
Related
Helo!
My goal is to retreive data from HPE Service Manager (HPSM). I use webBrowser component as it's seems the easyest way to me. At least I had no problem with authorization and opening search page but the things turned strange as I proceeded.
I need to find element with id "X13" on the page but
wb.document.getElementById("X13");
returns null although executing getElementById in IE and Chrome dev consoles still does the trick.
How can I find the element I need using C# and webBrowser component?
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.
I have an mvc app to test and my code works with Chrome but not Phantom. It can't find a simple input control with id = "password" on the logon page. I've tried different selectors, xpath, by class, by ID, even different controls on the page. It can find the "body" tag and the very next, but nothing is working to find anything past the next level in
I've also tried driver.waitforpageload and thread.sleep to make sure things are loaded first, no avail. Ideas anyone?
It can't find a simple input control with id = "password" on the logon
page.
and
It can find the "body" tag and the very next inside tag
"app-controller", but nothing is working to find anything past the
next level in, the view-manager tag.
and
I've even tested google.com to see if it was even loading and it can
find controls on that page successfully.
Considering the above, I'm guessing that the Login page is your page in your site after navigating to the URL.
I have encountered the same issue which normally led me think that PhantomJS cannot identify the elements on page. This until I started debugging stuff.
Because of the way how PhantomJS works loading everything headless, more or less in his own 'container' it turned out that it wasn't even able to load my test site, because it didn't had all the necessary prerequisites executed.
To be able to debug, and check if you face the same issue, just print to a log file the content of your page.
You can achieve this by using: var pageSource = driver.Pagesource;
It's highly likely that the last node present will be the body one.
If that's the case, you need to see what prerequisites are required for your site to start working: authentication, HTTPS certificates, etc.
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?
So I've been working learning how to use Selenium in C# to do some automated testing for a project. However, I've hit a roadblock on this one. I have been trying to figure out of way to click the following link on this webpage.
Here is what I'm trying to target:
<A class='PortalLink' HREF="https://mywebsite.com/myprograms/launchprogram.jsp?" onClick="setUser('login','password');"><span>MyProgram</span></A>
Searching by ClassName hasn't turned up anything. Although there are multiples, I just wanted to see if I could detect the presence of them.
By.ClassName("PortalLink")
I tried a href based search using CssSelector, but this failed as well.
By.CssSelector("[href*='https://mywebsite.com/myprograms/launchprogram.jsp?']")
Lastly, I tried to use XPath and search by class and span content, but this failed to find the link as well.
By.XPath("//A[contains(#class,'PortalLink') and span[text()='MyProgram']]")))
The webpage in question contains 2 frames which I've tried both.
I'm waiting 200 seconds before timing out. What am I doing incorrectly? Thanks in advance for any help!
Assuming that this element is not appended to the DOM during ajax, your statement should be
By.CssSelector("a.PortalLink[href*='launchprogram.jsp']")
If there are multiple of these links, then we'll need to go further up in the parent-child hierarchy since this link has no more attributes that make this link unique.
If you can post the parent html of this link then we can suggest more options,
Can you try these......
//span[contains(text(),'MyProgram']
//span[contains(text(),'MyProgram']/../