Skip to content

Commit

Permalink
Added section on ByChained (#1911)[deploy site]
Browse files Browse the repository at this point in the history
* Added section on ByChained

* moved code example to LocatorsTest.java

* fixed code example

* removed extra space

* changed code example lines

* changed code example lines

* changed code example lines

* changed code example lines

* Delete .vscode/settings.json

---------

Co-authored-by: Sri Harsha <[email protected]>
  • Loading branch information
shbenzer and harsha509 authored Sep 11, 2024
1 parent 03705be commit 985a9ba
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package dev.selenium.elements;

import org.openqa.selenium.By;
import org.openqa.selenium.support.pagefactory.ByChained;
import dev.selenium.BaseTest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class LocatorsTest extends BaseTest {

public String ByChainedTest() {
// Create instance of ChromeDriver
WebDriver driver = new ChromeDriver();
// Navigate to Url
driver.get("https://www.selenium.dev/selenium/web/login.html");

// Find username-field inside of login-form
By example = new ByChained(By.id("login-form"), By.id("username-field"));
WebElement username_input = driver.findElement(example);

//return placeholder text
String placeholder = username_input.getAttribute("placeholder");
return placeholder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ The FindElement makes using locators a breeze! For most languages,
all you need to do is utilize `webdriver.common.by.By`, however in
others it's as simple as setting a parameter in the FindElement function

### By

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
Expand Down Expand Up @@ -366,6 +368,32 @@ others it's as simple as setting a parameter in the FindElement function
{{< /tab >}}
{{< /tabpane >}}

### ByChained

The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="JavaScript" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Kotlin" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< /tabpane >}}

## Relative Locators

**Selenium 4** introduces Relative Locators (previously
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ The FindElement makes using locators a breeze! For most languages,
all you need to do is utilize `webdriver.common.by.By`, however in
others it's as simple as setting a parameter in the FindElement function

### By

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
Expand Down Expand Up @@ -356,7 +358,31 @@ others it's as simple as setting a parameter in the FindElement function
{{< /tab >}}
{{< /tabpane >}}

### ByChained

The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="JavaScript" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Kotlin" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< /tabpane >}}

## 相対ロケーター

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ The FindElement makes using locators a breeze! For most languages,
all you need to do is utilize `webdriver.common.by.By`, however in
others it's as simple as setting a parameter in the FindElement function

### By

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
Expand Down Expand Up @@ -359,6 +361,32 @@ others it's as simple as setting a parameter in the FindElement function
{{< /tab >}}
{{< /tabpane >}}

### ByChained

The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="JavaScript" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Kotlin" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< /tabpane >}}

## Relative Locators

**Selenium 4** introduces Relative Locators (previously
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ The FindElement makes using locators a breeze! For most languages,
all you need to do is utilize `webdriver.common.by.By`, however in
others it's as simple as setting a parameter in the FindElement function

### By

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
Expand Down Expand Up @@ -359,6 +361,32 @@ others it's as simple as setting a parameter in the FindElement function
{{< /tab >}}
{{< /tabpane >}}

### ByChained

The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="JavaScript" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Kotlin" text=true >}}
{{< badge-code >}}
{{< /tab >}}
{{< /tabpane >}}

## Relative Locators

**Selenium 4** introduces Relative Locators (previously
Expand Down

0 comments on commit 985a9ba

Please sign in to comment.