如何使用 selenium vba 在 PowerBI 页面中访问 signOn window 中的元素

How to access element within a signOn window within a PowerBI page with selenium vba

当我尝试通过 class 或 id 定位电子邮件元素时,它会抛出错误:

run-time error '438': object doesn't support this property or method

没有 iframe,而且我似乎也无法切换到 window(我看到的)。

这里是vba代码:

Set bot = New Selenium.ChromeDriver
   bot.start baseUrl:="https://app.powerbi.com/singleSignOn"
   bot.Get "/"
   Application.Wait Now + TimeValue("00:00:3")
   Dim FindBy As New Selenium.By

   With bot
    .FindElementsByCss(".pbi-text-input").Click
    .FindElementsById("email").SendKeys ("testing")
   end with

Html代码:

    </head>
    <body>
        <div id="emailCollection" class="emailBlock" style="display: none;"> <!-- The popup window -->
            <div class="emailLogoAndName">                
                <object type="image/svg+xml" data="13.0.17576.29/images/PowerBI_MasterLogo.svg"></object>
                <label>Power BI</label>
            </div>
            <div class="emailDetailArea">
                <div class="emailDetailHeader"><label>Enter your email, we&#39;ll check if you need to create a new account.</label></div>
                <div class="emailDetailContent">
                    <div class="emailDetailContentArea">
                        <div class="emailContentInput">
                            <div class="emailInputTitle">Email</div>
                            <div><input class="pbi-text-input" type="text" placeholder="Enter email" id="email"></div>
                            <div class="emailInputError" style="display: none;"></div>
                        </div>
                        <div class="emailContentDisclaimers">
                            <div class="emailDisclaimer1">
                                By proceeding you acknowledge that if you use your organization&#39;s email, your organization may have rights to access and manage your data and account.
                                <span class="learnMoreBtn" onmouseover="setPosition(event)">
                                    Learn more about using your organization&#39;s email
                                    <span class="learnMoreText">
                                        <b>Using your organization&#39;s email address to sign up</b>
                                        <p>If you use an email address provided by an organization you are affiliated with (like an employer or school), the owner of the email domain may (i) manage and administer your account, including modifying and terminating your access and (ii) access and process your data, including the contents of your communications and files. Your directory data (including name, signup date, and email) may be visible to other users of these services within your organization.
                                        </p>
                                    </span>
                                </span>
                            </div>
                            
                            <div class="emailDisclaimer2">
                                By clicking Submit, you agree to these <a href='https://go.microsoft.com/fwlink/?LinkID=870457&clcid=0x409' target='_blank'>terms and conditions</a> and allow Power BI to get your user and tenant details. <a href='https://go.microsoft.com/fwlink/?LinkID=521839&clcid=0x409' target='_blank'>Microsoft Privacy Statement</a>
                            </div>
                        </div>
                    </div>
                    <button class="pbi-fluent-button primary" id="submitBtn" onclick="submitEmail()">Submit</button>
                </div>
            </div>
            <div class="emailLogoArea">
                <object type="image/svg+xml" data="13.0.17576.29/images/PowerBI_MasterLogo.svg"></object>
            </div>
        </div>
    </body>
</html>

url: https://app.powerbi.com/singleSignOn

由于 website is 已启用,3 秒 可能不足以使元素可点击。

您可以将等待时间增加到 10 秒 并且您可以使用以下任一项 :

  • 使用 FindElementByCss:

    bot.FindElementByCss("input.pbi-text-input#email[placeholder='Enter email'][type='text']").SendKeys ("Red")
    
  • 使用 FindElementByXPath:

    bot.FindElementByXPath("//input[@class='pbi-text-input' and @id='email'][@placeholder='Enter email' and @type='text']").SendKeys ("Red")