Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xrmBrowser.LoginPage.Login not working #58

Closed
gohiljayraj opened this issue Dec 13, 2017 · 3 comments
Closed

xrmBrowser.LoginPage.Login not working #58

gohiljayraj opened this issue Dec 13, 2017 · 3 comments

Comments

@gohiljayraj
Copy link

xrmBrowser.LoginPage.Login is not working if CRM is configured for token-based authentication and have a custom page to login which pass security token and redirect to CRM.

@gohiljayraj
Copy link
Author

Below code opens the browser, inputs username and password and click submit button on login page. Page redirected to CRM Home page and after that I am getting below exception:
Code
string userName = ConfigurationManager.AppSettings["Uname"].ToString();
string password = ConfigurationManager.AppSettings["Pwd"].ToString();
Uri xrmUri = new Uri(ConfigurationManager.AppSettings["CrmUrl"].ToString());

        xrmBrowser.GoToXrmUri(xrmUri);            
        xrmBrowser.Driver.FindElement(By.Id("UsernameTextBox")).SendKeys(userName);
        xrmBrowser.Driver.FindElement(By.Id("PasswordTextBox")).SendKeys(password);

        xrmBrowser.Driver.ClickWhenAvailable(By.Id("SubmitButton"), new TimeSpan(0, 0, 2));
        xrmBrowser.Driver.WaitForPageToLoad();

Exception

OpenQA.Selenium.StaleElementReferenceException occurred
HResult=0x80131500
Message=Element is no longer valid
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.get_Location() at Microsoft.Dynamics365.UIAutomation.Browser.InteractiveBrowser.EventDriver_ElementClicked(Object sender, WebElementEventArgs e) at OpenQA.Selenium.Support.Events.EventFiringWebDriver.OnElementClicked(WebElementEventArgs e) at OpenQA.Selenium.Support.Events.EventFiringWebDriver.EventFiringWebElement.Click() at Microsoft.Dynamics365.UIAutomation.Browser.SeleniumExtensions.<>c__DisplayClass2_0.<ClickWhenAvailable>b__0(IWebDriver d) at Microsoft.Dynamics365.UIAutomation.Browser.SeleniumExtensions.WaitUntilClickable(IWebDriver driver, By by, TimeSpan timeout, Action1 successCallback, Action`1 failureCallback)
at Microsoft.Dynamics365.UIAutomation.Browser.SeleniumExtensions.ClickWhenAvailable(IWebDriver driver, By by, TimeSpan timeout)

@j621z
Copy link
Member

j621z commented Dec 18, 2017

@gohiljayraj This issue has been mitigated and will be pushed to GitHub soon.

@j621z j621z closed this as completed Dec 18, 2017
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
@dtu11 dtu11 mentioned this issue Dec 21, 2017
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
@tipsey
Copy link

tipsey commented Jun 20, 2018

Having similar issues with On-premise version:
OpenQA.Selenium.StaleElementReferenceException: 'stale element reference: element is not attached to the page document
(Session info: chrome=67.0.3396.87)
(Driver info: chromedriver=2.40.565498

Debug errors here:
public static IWebElement ClickWhenAvailable(this IWebDriver driver, By by, TimeSpan timeout)
{
var element = driver.FindElement(by);

        WaitUntilClickable(driver,
                            by,
                            timeout,
                            d => { element.Click(); },
                            e => { throw new InvalidOperationException($"Unable to click element."); });



        return element;
    }

` [TestClass]
public class CustomLogin
{
string _username = System.Configuration.ConfigurationManager.AppSettings["OnlineUsername"].ToString();
string _password = System.Configuration.ConfigurationManager.AppSettings["OnlinePassword"].ToString();
Uri _xrmUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["OnlineCrmUrl"].ToString());

    [TestMethod]
    public void TestCustomLogin()
    {
        using (var xrmBrowser = new XrmBrowser(TestSettings.Options))
        {
            xrmBrowser.GoToXrmUri(_xrmUri);
            xrmBrowser.Driver.WaitForPageToLoad();

            ///Set Username, password and click Submit button
            xrmBrowser.Driver.FindElement(By.Id("ContentPlaceHolder1_UsernameTextBox")).SendKeys(_username);
            xrmBrowser.ThinkTime(1000);
            xrmBrowser.Driver.FindElement(By.Id("ContentPlaceHolder1_PasswordTextBox")).SendKeys(_password);
            xrmBrowser.ThinkTime(1000);

            xrmBrowser.Driver.ClickWhenAvailable(By.Id("ContentPlaceHolder1_SubmitButton")).Click();
            xrmBrowser.Driver.WaitForPageToLoad();

        }
    }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants