简体   繁体   English

Robot Framework / Selenium 中的子元素数量?

[英]Number of child elements in Robot Framework / Selenium?

How to find the total number of elements/tags present under specific tag ?如何找到特定标签下存在的元素/标签总数?

<div id="mainTag class='mainTag'>
     <div id="subMainTag1" class="subMainTag1">
         <div id="subTag1" class="subTag1">
              <div some inner tags again>
                  <div some inner tags again>
         <div id="subTag1" class="subTag1">
               <div some inner tags again>
                  <div some inner tags again>
         <div id="subTag1" class="subTag1">
                <div some inner tags again>
                  <div some inner tags again>
         <div id="subTag1" class="subTag1">
                <div some inner tags again>
                  <div some inner tags again>

I am looking for div tags having id and class subTag1 .As per snippet provided above, i need to get the count value as 4 .我正在寻找具有idclass subTag1 div标签。根据上面提供的片段,我需要将计数值设为4 verifyXpathCount does not return the counts. verifyXpathCount不返回计数。

storeXpathCount | //div[@id='mainTag']/div[@id='subMainTag1']/div | count
echo ${count}

storeXpathCount | //div[@id='mainTag']/div[@id='subMainTag1']//div | count
echo ${count}

storeXpathCount | //div[@id='mainTag']/div[@id='subMainTag1']/* | count
echo ${count}

All above returns 0 , Nothing returns actual value 4 .以上所有返回0 ,Nothing 返回实际值4 Not sure, what i am missing here.不确定,我在这里缺少什么。

Selenium IDE/web-driver:python , anything is fine. Selenium IDE/web-driver:python ,一切都很好。

ANSWER: storeXpathCount working fine.答案: storeXpathCount工作正常。 I had missed to select frame.我错过了选择框架。 Get Matching XPath Count also works fine in Robot Framework. Get Matching XPath Count在 Robot Framework 中也能正常工作。

Adding to kjhughes's answer , since he didn't understand you were trying to achieve this using Robot Framework.添加到kjhughes 的回答中,因为他不明白您正在尝试使用 Robot Framework 来实现这一目标。 It wasn't that clear, to his defense.这不是很清楚,为他辩护。

Using the XPath he provided, you could use the Xpath Should Match X Times keyword.使用他提供的 XPath,您可以使用Xpath 应该匹配 X 次关键字。 Something like this:像这样的东西:

XPath Should Match X Times    //div[@id='mainTag']/*    4

If you need to store the retrieved matching count, you can use the quite similar keyword, Get Matching XPath Count , like this:如果需要存储检索到的匹配计数,可以使用非常相似的关键字Get Matching XPath Count ,如下所示:

${count}=    Get Matching XPath Count    //div[@id='mainTag']/*

This XPath,这个 XPath,

count(//div[@id='mainTag']/*)

will return the number of child elements under the div element with id attribute value of mainTag .将返回id属性值为mainTagdiv元素下的子元素数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM