从md-card中提取字符串值

时间:2018-02-25 20:57:52

标签: c# selenium xpath selenium-webdriver nunit

我想使用Selenium从md-card中提取字符串值(已成功验证电子邮件!)。

<md-card ng-if="$ctrl.isMyCompany &amp;&amp; $ctrl.showVerified" class="ng-scope _md">
    <md-card-content class="tradingPartnerVerification-warn ng-binding layout-align-start-center" layout-align="start center">
        <md-icon class="myCompany-verifiedEmailIcon" md-svg-icon="check-circle" role="img" aria-label="check-circle">
            <svg xmlns="http://www.w3.org/2000/svg" fit="" height="100%" width="100%" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24" focusable="false">
                <g id="check-circle">
                    <path d="M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M11,16.5L18,9.5L16.59,8.09L11,13.67L7.91,10.59L6.5,12L11,16.5Z"></path>
                </g>
            </svg>
        </md-icon>
        Email is verified successfully!
    </md-card-content>
</md-card>

我使用.Net和NUnit框架。我的代码如下。

string ActualEmailVerifiedText = diver.FindElement(By.XPath("//md-card-content[@class='tradingPartnerVerification-warn ng-binding layout-align-start-center']")).Text;

2 个答案:

答案 0 :(得分:0)

我认为有可能在运行时NoSuchElementException: no such element: Unable to locate element:中添加了一些类(假设你只是错误地驱动程序

试试这个:

md-card-content

答案 1 :(得分:0)

要提取字符串电子邮件已成功验证!,您需要引导 WebDriverWait ,以便在 HTML 中呈现文本,如下所示:< / p>

wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
string myElement = wait.Until(ExpectedConditions.TextToBePresentInElementLocated(By.XPath("//md-card[@class='ng-scope _md']/md-card-content[@class='tradingPartnerVerification-warn ng-binding layout-align-start-center']"),"Email is verified successfully!"));
Console.WriteLine(myElement.Text);