0

So I clicked on a sign in button with selenium c# and it open up a pop up window saying choose account. I want to click on the option use another account but it wont work.

i tried using driver.FindElement(By.Id("otherTile")).Click(); but it wont work. i also triewd using the window handler but it didnt work. here is the html code .

                   <div id="otherTile" class="table" tabindex="0" role="button" aria-labelledby="otherTileText" data-bind="
                css: { 'list-item': svr.fSupportWindowsStyles },
                click: otherTile_onClick,
                pressEnter: otherTile_onClick">
                <div class="table-row">
                    <div class="table-cell tile-img">
                        <img class="tile-img" role="presentation" pngsrc="https://aadcdn.msauth.net/shared/1.0/content/images/picker_account_add_c9929da7ed2c1ed4745e4035cf5441cd.png" svgsrc="https://aadcdn.msauth.net/shared/1.0/content/images/picker_account_add_56e73414003cdb676008ff7857343074.svg" data-bind="imgSrc" src="https://aadcdn.msauth.net/shared/1.0/content/images/picker_account_add_56e73414003cdb676008ff7857343074.svg">
                    </div>

                    <div class="table-cell text-left content" data-bind="css: { 'content': !svr.fSupportWindowsStyles }">
                        <div id="otherTileText" data-bind="text: otherTileText">Use another account</div>
                    </div>
                </div>
            </div>
ghosty
  • 1
  • 1

1 Answers1

0

The element seems to be a dynamic element within a popup you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:

  • Using CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div.table#otherTile[aria-labelledby='otherTileText']"))).Click();
    
  • Using XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='table' and @id='otherTile'][@[aria-labelledby='otherTileText']"))).Click();
    

Update

Incase you are using DotNetSeleniumExtras.WaitHelpers with nuget:

new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='table' and @id='otherTile'][@[aria-labelledby='otherTileText']"))).Click();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352