Skip to content

Latest commit

 

History

History
330 lines (268 loc) · 12 KB

File metadata and controls

330 lines (268 loc) · 12 KB
title Web要素に関する情報
linkTitle 情報
weight 4
description 要素について学ぶことができること。

特定の要素についてクエリできる詳細情報がいくつかあります。

表示されているかどうか

This method is used to check if the connected Element is displayed on a webpage. Returns a Boolean value, True if the connected element is displayed in the current browsing context else returns false.

This functionality is mentioned in, but not defined by the w3c specification due to the impossibility of covering all potential conditions. As such, Selenium cannot expect drivers to implement this functionality directly, and now relies on executing a large JavaScript function directly. This function makes many approximations about an element's nature and relationship in the tree to return a value.

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L20-L24" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L12-L15" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L18-L22" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L12">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L16-L17">}} {{< /tab >}} {{< tab header="Kotlin" >}}

//navigates to url driver.get("https://www.selenium.dev/selenium/web/inputs.html")

//returns true if element is displayed else returns false val flag = driver.findElement(By.name("email_input")).isDisplayed()

{{< /tab >}} {{< /tabpane >}}

要素が有効か

このメソッドは、接続された要素がWebページで有効または無効になっているかどうかを確認するために使います。 ブール値を返し、現在のブラウジングコンテキストで接続されている要素が 有効(enabled) になっている場合は True 、そうでない場合は false を返します。

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L27-L29" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L19" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L25-L27" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L17">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L23-L24">}} {{< /tab >}} {{< tab header="Kotlin" >}} //navigates to url driver.get("https://www.selenium.dev/selenium/web/inputs.html")

//returns true if element is enabled else returns false val attr = driver.findElement(By.name("button_input")).isEnabled() {{< /tab >}} {{< /tabpane >}}

要素が選択されているかどうか

このメソッドは、参照された要素が選択されているかどうかを判断します。 このメソッドは、チェックボックス、ラジオボタン、入力要素、およびオプション要素で広く使われています。

ブール値を返し、現在のブラウジングコンテキストで参照された要素が 選択されている 場合は True 、そうでない場合は false を返します。

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L32-L34" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L23" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L30-L32" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L22">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L30-L31">}} {{< /tab >}} {{< tab header="Kotlin" >}} //navigates to url driver.get("https://www.selenium.dev/selenium/web/inputs.html")

//returns true if element is checked else returns false val attr = driver.findElement(By.name("checkbox_input")).isSelected() {{< /tab >}} {{< /tabpane >}}

要素のタグ名を取得

これは、現在のブラウジングコンテキストにフォーカスがある参照された要素の TagName を取得するために使います。

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L37-L39" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L27" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L35-L37" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L27">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L37-L38">}} {{< /tab >}} {{< tab header="Kotlin" >}} //navigates to url driver.get("https://www.selenium.dev/selenium/web/inputs.html")

//returns TagName of the element val attr = driver.findElement(By.name("email_input")).getTagName() {{< /tab >}} {{< /tabpane >}}

要素矩形を取得

参照される要素の寸法と座標を取得するために使います。

取得データのbodyには、次の詳細が含まれます。

  • 要素の左上隅からのx軸の位置
  • 要素の左上隅からのy軸の位置
  • 要素の高さ
  • 要素の幅

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L42-L44" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L31" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L40-L43" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L32">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L45">}} {{< /tab >}} {{< tab header="Kotlin" >}} // Navigate to url driver.get("https://www.selenium.dev/selenium/web/inputs.html")

// Returns height, width, x and y coordinates referenced element val res = driver.findElement(By.name("range_input")).rect

// Rectangle class provides getX,getY, getWidth, getHeight methods println(res.getX()) {{< /tab >}} {{< /tabpane >}}

要素のCSSの値を取得

現在のブラウジングコンテキスト内の要素の指定された計算したスタイル属性の値を取得します。

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L49-L50" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L35-L37" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L49-L50" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L38">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L76-L78">}} {{< /tab >}} {{< tab header="Kotlin" >}} // Navigate to Url driver.get("https://www.selenium.dev/selenium/web/colorPage.html")

// Retrieves the computed style property 'color' of linktext val cssValue = driver.findElement(By.id("namedColor")).getCssValue("background-color") {{< /tab >}} {{< /tabpane >}}

要素テキストを取得

指定された要素のレンダリングされたテキストを取得します。

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L54-L56" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L41" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L53-L55" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L43">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L84-L86">}} {{< /tab >}} {{< tab header="Kotlin" >}} // Navigate to URL driver.get("https://www.selenium.dev/selenium/web/linked_image.html")

// retrieves the text of the element val text = driver.findElement(By.id("justanotherlink")).getText() {{< /tab >}} {{< /tabpane >}}

Fetching Attributes and Properties

Get Attribute

Fetches the run time value associated with a DOM attribute. It returns the data associated with the DOM attribute or property of the element.

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L60-L64" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/elements/test_information.py#L44-L46" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/InformationTest.cs#L58-L62" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L48">}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L55-L59">}} {{< /tab >}} {{< tab header="Kotlin" >}} // Navigate to URL driver.get("https://www.selenium.dev/selenium/web/inputs.html")

//fetch the value property associated with the textbox val attr = driver.findElement(By.name("email_input")).getAttribute("value") {{< /tab >}} {{< /tabpane >}}

Get Dom Property

This method retrieves the value of a specific DOM property of a web element.

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L67-L69" >}} {{< /tab >}} {{< tab header="Python" text=true >}}

{{< /tab >}} {{< tab header="CSharp" text=true >}}

{{< /tab >}} {{< tab header="Ruby" text=true >}}

{{< /tab >}} {{< tab header="JavaScript" text=true >}}

{{< /tab >}} {{< tab header="Kotlin" >}}

{{< /tab >}} {{< /tabpane >}}

Get Dom Attribute

This method retrieves the value of a specific HTML attribute of a web element

{{< tabpane langEqualsHeader=true >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/InformationTest.java#L71-L73" >}} {{< /tab >}} {{< tab header="Python" text=true >}}

{{< /tab >}} {{< tab header="CSharp" text=true >}}

{{< /tab >}} {{< tab header="Ruby" text=true >}}

{{< /tab >}} {{< tab header="JavaScript" text=true >}}

{{< /tab >}} {{< tab header="Kotlin" >}}

{{< /tab >}} {{< /tabpane >}}