本ページには広告が含まれています。
WebElementsコレクション内の指定したインデックスにあるWebElement オブジェクトを返します。
- 構文
- WebElement = WebElements.Item( index )
- 引数
- index (Long)必須
- 1から始まるインデックス
WebElements オブジェクトを返すメソッド・プロパティ
- WebElements.Item プロパティ
- 指定されたロケータに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたロケータと値に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたCSSクラスに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたCSSセレクタに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたid属性に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたリンクテキストに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたname属性に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたリンクテキストの部分に一致するすべてのWebElements オブジェクトを取得します。
- WebDriver.FindElementsByTag メソッド
- 指定されたタグ名に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定された XPath クエリに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたロケータに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたロケータと値に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたCSSクラスに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたCSSセレクタに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたid属性に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたリンクテキストに一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたname属性に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたリンクテキストの部分に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定されたタグ名に一致するすべてのWebElements オブジェクトを取得します。
- WebElements.Item プロパティ
- 指定された XPath クエリに一致するすべてのWebElements オブジェクトを取得します。
使い方
WebElementsコレクションの要素数を取得
indexに指定できる値は1からWebElements.Count プロパティで返す範囲の数値です。
PRINT WebElements.Count
以下はExample Domainのページ内にあるpタグの数を取得します。
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
DIM WebDriver = CREATEOLEOBJ("Selenium.WebDriver")
WebDriver.Start("chrome")
WebDriver.Get("https://example.com")
DIM WebElements = WebDriver.FindElementsByTag("p")
PRINT WebElements.Count
- 結果
2
特定の要素にアクセス
WebElementsコレクションから特定の要素にアクセスするにはWebElements.Item プロパティで取得する要素のインデックスを指定します。
以下はExample Domainのページ内からpタグにアクセスしています。WebElements.Item プロパティの引数に1を指定しているので、1つ目に見つかったpタグの内容が返されます。
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
DIM WebDriver = CREATEOLEOBJ("Selenium.WebDriver")
WebDriver.Start("chrome")
WebDriver.Get("https://example.com")
DIM WebElements = WebDriver.FindElementsByTag("p")
DIM WebElement = WebElements.Item(1)
PRINT WebElement.text
- 結果
This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.