FindElementByName - Element couldn't be located
See original GitHub issueHi,
I have a test which passes in Visual Studio debug mode but fails when it is run as normal. The test is:
AppSession.FindElementByAccessibilityId("UsernameTextBox").SendKeys("login");
AppSession.FindElementByAccessibilityId("PasswordTextBox").SendKeys("password");
var loginButton = AppSession.FindElementByAccessibilityId("LoginButton");
loginButton.Click();
AppSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(5000));
var window = AppSession.FindElementByName(windowName);
Assert.IsNotNull(window);
This code is run on test initialization:
private const string ServerURL = "http://127.0.0.1:4723";
protected DesiredCapabilities AppCapabilities { get; set; }
protected WindowsDriver<WindowsElement> AppSession { get; set; }
protected void InitApplication()
{
AppCapabilities = new DesiredCapabilities();
AppCapabilities.SetCapability("app", $"{Environment.CurrentDirectory}\\app.exe");
AppSession = new WindowsDriver<WindowsElement>(new Uri(ServerURL), AppCapabilities);
}
When I put breakpoint on the line
var window = AppSession.FindElementByName(windowName);
then test passes in debug mode. Otherwise it fails with exception System.InvalidOperationException: An element could not be located on the page using the given search parameters.
After login button is clicked the Window is maximized and it’s name gets updated.
Any help?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Element not Interactable when using the selenium function ...
I have webpage where I am trying to login to it. When I use find element by name method to find the elements...
Read more >Selenium can't locate element by xpath
To solve this you should wait till the webelement gets loaded on to the webpage. One way to do this to use WebDriverWait...
Read more >F5 LTM SOAP API - Ruby f5-icontrol Gem - Could not...
Regarding the "couldn't find element by name" error, that means that the server didn't see the specific parameter in the request. In your...
Read more >Unable to locate an element using xpath error in selenium- ...
We may encounter the error - unable to locate element while working with Selenium webdriver. This leads to NoSuchElementException.
Read more >Problem with find Element - Issues/Bugs
I want to test it on a List, the elements i want to find are visible. ... {“status”:7,“value”:{“message”:“An element could not be located...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lekso81 - here’s how I accomplished this in C# for a login workflow scenario. After login, the code waits for the main window using the DefaultWait which will try to find the element every 1 second until it finds it or until the timeout expires…
…not sure if this is best approach, but it works better than Thread.Sleep() IMHO since I cannot control how long it might actually take for the login process to complete and the main window to finally open.
Hi,
thank you for your responses. My tests now pass, but only a Thread.Sleep(5000) statement after Click event helps. The WaitForElementToExist function doesn’t work and always returns null. This is what I implemented using recommendation from PandaMagnus:
It is used as: