簡體   English   中英

如何在Selenium C#中獲取相同類/屬性的值?

[英]How to get values of same class/properties in Selenium C#?

我目前正在自動執行測試,以比較摘要頁面上的預期認可和實際認可。

我如何閱讀摘要頁面上顯示的頁面上的所有認可值。這些值可以更改,這意味着根據不同的輸入可以有2-5個值。 我嘗試過Xpath和CSS選擇器,但是沒有運氣。 這是兩個背書的元素屬性,其余背書將具有相同的屬性(明智的元素),只是值不同。

我希望能夠獲得頁面上列出的所有認可,因此我可以將其輸入到我的Excel工作表中,以與預期認可進行比較。

背書1:

         <div class="guidance smaller ng-scope" ng-repeat="end in 
          prop.Endorsements">
          <a ng-href="#c03770af-3724-4c3a-a240-e341c0d2c3ef" ng-bind-
          html="end.Name" class="ng-binding" href="#c03770af-3724-4c3a-
          a240-e341c0d2c3ef">Restricted Theft</a>
          </div>
          <a ng-href="#c03770af-3724-4c3a-a240-e341c0d2c3ef" ng-bind-
          html="end.Name" class="ng-binding" href="#c03770af-3724-4c3a-a240-
          e341c0d2c3ef">Restricted Theft</a>

背書2:

       <div class="guidance smaller ng-scope" ng-repeat="end in 
       prop.Endorsements">
       <a ng-href="#93ff9067-f64c-4879-933d-8b0a1d077e74" ng-bind-
        html="end.Name" class="ng-binding" href="#93ff9067-f64c-4879-933d-
        8b0a1d077e74">Malicious Damage Exclusion</a>
        </div>
         <a ng-href="#93ff9067-f64c-4879-933d-8b0a1d077e74" ng-bind-
         html="end.Name" class="ng-binding" href="#93ff9067-f64c-4879-933d-
         8b0a1d077e74">Malicious Damage Exclusion</a>

您需要一個XPath表達式來一次捕獲所有a元素並將它們存儲在列表中。

如果沒有其他錨標簽,則認可:

IList<IWebElement> listOfEndorsements= Driver.FindElements(By.XPath("//a"));

如果還有其他錨標記,則可以嘗試:

IList<IWebElement> listOfEndorsements= Driver.FindElements(By.XPath("//div[contains(@ng-repeat,'prop.Endorsements')]/a"));

然后,您可以使用ForEach循環從IWebElements列表中提取所需的信息。

foreach (var endorsement in listOfEndorsements)
{
    var text = endorsement.Text;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM