Skip to content

Commit 985a9ba

Browse files
shbenzerharsha509
andauthored
Added section on ByChained (#1911)[deploy site]
* 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]>
1 parent 03705be commit 985a9ba

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
package dev.selenium.elements;
2-
2+
import org.openqa.selenium.By;
3+
import org.openqa.selenium.support.pagefactory.ByChained;
34
import dev.selenium.BaseTest;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.chrome.ChromeDriver;
48

59
public class LocatorsTest extends BaseTest {
610

11+
public String ByChainedTest() {
12+
// Create instance of ChromeDriver
13+
WebDriver driver = new ChromeDriver();
14+
// Navigate to Url
15+
driver.get("https://www.selenium.dev/selenium/web/login.html");
16+
17+
// Find username-field inside of login-form
18+
By example = new ByChained(By.id("login-form"), By.id("username-field"));
19+
WebElement username_input = driver.findElement(example);
20+
21+
//return placeholder text
22+
String placeholder = username_input.getAttribute("placeholder");
23+
return placeholder;
24+
}
725
}

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.en.md

+28
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ The FindElement makes using locators a breeze! For most languages,
336336
all you need to do is utilize `webdriver.common.by.By`, however in
337337
others it's as simple as setting a parameter in the FindElement function
338338

339+
### By
340+
339341
{{< tabpane langEqualsHeader=true >}}
340342
{{< badge-examples >}}
341343
{{< tab header="Java" >}}
@@ -366,6 +368,32 @@ others it's as simple as setting a parameter in the FindElement function
366368
{{< /tab >}}
367369
{{< /tabpane >}}
368370

371+
### ByChained
372+
373+
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.
374+
375+
{{< tabpane langEqualsHeader=true >}}
376+
{{< badge-examples >}}
377+
{{< tab header="Java" >}}
378+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
379+
{{< /tab >}}
380+
{{< tab header="Python" text=true >}}
381+
{{< badge-code >}}
382+
{{< /tab >}}
383+
{{< tab header="CSharp" text=true >}}
384+
{{< badge-code >}}
385+
{{< /tab >}}
386+
{{< tab header="Ruby" text=true >}}
387+
{{< badge-code >}}
388+
{{< /tab >}}
389+
{{< tab header="JavaScript" text=true >}}
390+
{{< badge-code >}}
391+
{{< /tab >}}
392+
{{< tab header="Kotlin" text=true >}}
393+
{{< badge-code >}}
394+
{{< /tab >}}
395+
{{< /tabpane >}}
396+
369397
## Relative Locators
370398

371399
**Selenium 4** introduces Relative Locators (previously

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.ja.md

+26
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ The FindElement makes using locators a breeze! For most languages,
326326
all you need to do is utilize `webdriver.common.by.By`, however in
327327
others it's as simple as setting a parameter in the FindElement function
328328

329+
### By
330+
329331
{{< tabpane langEqualsHeader=true >}}
330332
{{< badge-examples >}}
331333
{{< tab header="Java" >}}
@@ -356,7 +358,31 @@ others it's as simple as setting a parameter in the FindElement function
356358
{{< /tab >}}
357359
{{< /tabpane >}}
358360

361+
### ByChained
362+
363+
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.
359364

365+
{{< tabpane langEqualsHeader=true >}}
366+
{{< badge-examples >}}
367+
{{< tab header="Java" >}}
368+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
369+
{{< /tab >}}
370+
{{< tab header="Python" text=true >}}
371+
{{< badge-code >}}
372+
{{< /tab >}}
373+
{{< tab header="CSharp" text=true >}}
374+
{{< badge-code >}}
375+
{{< /tab >}}
376+
{{< tab header="Ruby" text=true >}}
377+
{{< badge-code >}}
378+
{{< /tab >}}
379+
{{< tab header="JavaScript" text=true >}}
380+
{{< badge-code >}}
381+
{{< /tab >}}
382+
{{< tab header="Kotlin" text=true >}}
383+
{{< badge-code >}}
384+
{{< /tab >}}
385+
{{< /tabpane >}}
360386

361387
## 相対ロケーター
362388

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md

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

332+
### By
333+
332334
{{< tabpane langEqualsHeader=true >}}
333335
{{< badge-examples >}}
334336
{{< tab header="Java" >}}
@@ -359,6 +361,32 @@ others it's as simple as setting a parameter in the FindElement function
359361
{{< /tab >}}
360362
{{< /tabpane >}}
361363

364+
### ByChained
365+
366+
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.
367+
368+
{{< tabpane langEqualsHeader=true >}}
369+
{{< badge-examples >}}
370+
{{< tab header="Java" >}}
371+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
372+
{{< /tab >}}
373+
{{< tab header="Python" text=true >}}
374+
{{< badge-code >}}
375+
{{< /tab >}}
376+
{{< tab header="CSharp" text=true >}}
377+
{{< badge-code >}}
378+
{{< /tab >}}
379+
{{< tab header="Ruby" text=true >}}
380+
{{< badge-code >}}
381+
{{< /tab >}}
382+
{{< tab header="JavaScript" text=true >}}
383+
{{< badge-code >}}
384+
{{< /tab >}}
385+
{{< tab header="Kotlin" text=true >}}
386+
{{< badge-code >}}
387+
{{< /tab >}}
388+
{{< /tabpane >}}
389+
362390
## Relative Locators
363391

364392
**Selenium 4** introduces Relative Locators (previously

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md

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

332+
### By
333+
332334
{{< tabpane langEqualsHeader=true >}}
333335
{{< badge-examples >}}
334336
{{< tab header="Java" >}}
@@ -359,6 +361,32 @@ others it's as simple as setting a parameter in the FindElement function
359361
{{< /tab >}}
360362
{{< /tabpane >}}
361363

364+
### ByChained
365+
366+
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.
367+
368+
{{< tabpane langEqualsHeader=true >}}
369+
{{< badge-examples >}}
370+
{{< tab header="Java" >}}
371+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}}
372+
{{< /tab >}}
373+
{{< tab header="Python" text=true >}}
374+
{{< badge-code >}}
375+
{{< /tab >}}
376+
{{< tab header="CSharp" text=true >}}
377+
{{< badge-code >}}
378+
{{< /tab >}}
379+
{{< tab header="Ruby" text=true >}}
380+
{{< badge-code >}}
381+
{{< /tab >}}
382+
{{< tab header="JavaScript" text=true >}}
383+
{{< badge-code >}}
384+
{{< /tab >}}
385+
{{< tab header="Kotlin" text=true >}}
386+
{{< badge-code >}}
387+
{{< /tab >}}
388+
{{< /tabpane >}}
389+
362390
## Relative Locators
363391

364392
**Selenium 4** introduces Relative Locators (previously

0 commit comments

Comments
 (0)