Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added section on ByChained #1911

Merged
merged 15 commits into from
Sep 11, 2024
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
Loading