Skip to content

added the locator file for c# - #2855

Open
rpallavisharma wants to merge 14 commits into
SeleniumHQ:trunkfrom
rpallavisharma:csharp-loc-pal
Open

rpallavisharma wants to merge 14 commits into
SeleniumHQ:trunkfrom
rpallavisharma:csharp-loc-pal

Conversation

@rpallavisharma

@rpallavisharma rpallavisharma commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

added locator.cs file and added code lines in all languages

Motivation and Context

it completes locator information for csharp

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

@netlify

netlify Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

👷 Deploy request for selenium-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 5130ec2

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Link C# locator documentation to a shared test example

✨ Enhancement 📝 Documentation 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds C# examples for standard, combined, and chained element locators.
• Replaces inline C# snippets with source-linked examples across four documentation locales.
• The new test currently contains C# compilation errors and needs correction before its examples are
 usable.
Diagram

graph TD
  Test["C# locator test"] --> Snippets["Source line ranges"] --> English["English docs"]
  Snippets --> Localized["Translated docs"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use the existing BaseTest fixture and separate test methods
  • ➕ Reuses driver cleanup and isolates locator failures.
  • ➕ Keeps documentation snippets backed by independently runnable tests.
  • ➖ Requires managing more source line ranges in the documentation.

Recommendation: Keep source-linked snippets rather than duplicating inline examples, but use the existing BaseTest fixture and split the locator checks into valid C# tests. As written, repeated local declarations, Java-style method calls and identifiers, and an invalid assertion prevent the test from compiling, so the linked examples are not yet reliable.

Files changed (5) +125 / -99

Tests (1) +59 / -1
LocatorsTest.csAdd C# locator examples in one test method +59/-1

Add C# locator examples in one test method

• Adds ChromeDriver-based examples and assertions for eight basic locator strategies plus ByAll and ByChained. Removes BaseTest inheritance and manages the driver directly. The method contains repeated local declarations and Java-style API usage that prevent compilation.

examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs

Documentation (4) +66 / -98
locators.en.mdSource English C# locator snippets from the test +18/-26

Source English C# locator snippets from the test

• Replaces eight inline C# basic-locator examples with gh-codeblock references. Adds references for the ByChained and ByAll sections in place of code placeholders.

website_and_docs/content/documentation/webdriver/elements/locators.en.md

locators.ja.mdSource Japanese-page C# snippets from the test +16/-24

Source Japanese-page C# snippets from the test

• Replaces eight inline C# basic-locator examples with line-range references to LocatorsTest.cs. No translated prose changes.

website_and_docs/content/documentation/webdriver/elements/locators.ja.md

locators.pt-br.mdSource Portuguese-page C# snippets from the test +16/-24

Source Portuguese-page C# snippets from the test

• Replaces eight inline C# basic-locator examples with line-range references to LocatorsTest.cs. No translated prose changes.

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

locators.zh-cn.mdSource Chinese-page C# snippets from the test +16/-24

Source Chinese-page C# snippets from the test

• Replaces eight inline C# basic-locator examples with line-range references to LocatorsTest.cs. No translated prose changes.

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

@qodo-code-review

qodo-code-review Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again manually by commenting /agentic_review on this PR.

Grey Divider

Qodo Logo

@diemol diemol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the code comments, and there is also a block of code that is commented. Should it be part of the PR, or is it just left out?

@rpallavisharma

Copy link
Copy Markdown
Member Author

@diemol , sorry i was waiting for information about c# methods which are not there in selenium lib as per @nvborisenko mentioned. i commented that code thats why. i will need to remove it and then update line numbers in all files. will be fixing it all in sometime. i was considering what would be best here. first i thought let code exist but in comment, but its not correct i believe.
maybe some text change particular to c# will be required.
need sometime. will request review again.

@rpallavisharma
rpallavisharma requested review from diemol and removed request for AutomatedTester October 7, 2026 05:27
@rpallavisharma

Copy link
Copy Markdown
Member Author

@diemol i have removed comments. for C# by.all and by.chained are not in the default lib. they are part of - https://github.com/DotNetSeleniumTools/DotNetSeleniumExtras . unsure but @nvborisenko mentioned selenium no longer support it. Let me know if anything is required to be changed here. thanks

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (2) 📜 Skill insights (0)

Grey Divider


Action required

1. C# references keep forbidden indentation 📘 Rule violation ⚙ Maintainability
Description
The newly added gh-codeblock directives for the C# tabs are preceded by spaces instead of starting
at the document margin. This affects the C# examples in all four localized locator pages and can
prevent the shortcode from rendering as the intended runnable example.
Code

website_and_docs/content/documentation/webdriver/elements/locators.en.md[86]

+  {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs#L20-L21" >}}
Evidence
The checklist requires runnable snippets to use non-indented gh-codeblock lines. The added C#
directive in the English page begins with leading spaces, and the localized pages contain the same
pattern with varying indentation.

AGENTS.md: Follow Documentation Prose and Code Example Conventions
website_and_docs/content/documentation/webdriver/elements/locators.en.md[86-86]
website_and_docs/content/documentation/webdriver/elements/locators.ja.md[114-114]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new C# `gh-codeblock` directives are indented, contrary to the documentation convention requiring shortcode lines to start at the document margin.

## Fix Focus Areas
- website_and_docs/content/documentation/webdriver/elements/locators.en.md[86-86]
- website_and_docs/content/documentation/webdriver/elements/locators.ja.md[84-284]
- website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md[87-287]
- website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md[87-287]

## Recommended Fix
Remove the leading spaces from every newly added C# `gh-codeblock` directive in the four localized locator pages while preserving the surrounding tab shortcodes and referenced line ranges.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


2. Disabled C# references point to missing lines 📘 Rule violation ⚙ Maintainability
Description
The added commented gh-codeblock references in the Japanese, Brazilian Portuguese, and Simplified
Chinese pages target lines 52-61 of LocatorsTest.cs, but that example file ends at line 47. A
maintainer who re-enables either reference gets a missing range instead of the intended C# example,
leaving the documentation reference unsynchronized.
Code

website_and_docs/content/documentation/webdriver/elements/locators.ja.md[351]

+  <!-- {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs#L58-L61" >}} -->
Evidence
The checklist requires documentation references and gh-codeblock ranges to match the current
example files. The added comments reference lines 52-55 and 58-61, while the changed C# example
contains only lines 1-47.

AGENTS.md: Keep Documentation Code References Synchronized with Examples
examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[1-47]
website_and_docs/content/documentation/webdriver/elements/locators.ja.md[351-351]
website_and_docs/content/documentation/webdriver/elements/locators.ja.md[378-378]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The localized documentation contains commented C# `gh-codeblock` references to line ranges that do not exist in the current example file.

## Fix Focus Areas
- website_and_docs/content/documentation/webdriver/elements/locators.ja.md[351-351]
- website_and_docs/content/documentation/webdriver/elements/locators.ja.md[378-378]
- website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md[354-354]
- website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md[381-381]
- website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md[354-354]
- website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md[381-381]
- examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[1-47]

## Recommended Fix
Remove the stale commented shortcode references, or update them to valid ranges only if the corresponding C# examples are restored; do not leave references to lines beyond the end of the example file.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗



Remediation recommended

3. Failed locator tests leave browsers running 🐞 Bug ☼ Reliability
Description
TestLocatorCommands calls driver.Quit() only after every navigation, lookup and assertion
succeeds, while LocatorsTest no longer inherits the cleanup in BaseTest. If any earlier step
throws, the test exits without closing its Chrome session, including during test retries.
Code

examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[44]

+            driver.Quit();
Evidence
The new test performs all browser operations before its sole Quit() call. BaseTest supplies
[TestCleanup] that quits the driver, but the changed class declaration does not inherit it; the
.NET workflow runs tests with retries.

examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[9-44]
examples/dotnet/SeleniumDocs/BaseTest.cs[25-33]
.github/workflows/dotnet-examples.yml[85-97]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new locator test skips `Quit()` when navigation, a lookup, or an assertion fails.
## Fix Focus Areas
- examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[10-44]
## Recommended Fix
Use the existing `BaseTest` driver lifecycle, or place the locally created driver's `Quit()` in a `finally` block.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


4. C# locator examples lack driver setup 🐞 Bug ≡ Correctness
Description
The new gh-codeblock ranges show calls on driver but omit the ChromeDriver creation at line
15; the seven later ranges also assign to element without showing its declaration. Readers copying
an individual C# tab into a method get undefined variables, whereas the replaced inline tabs
included driver creation.
Code

website_and_docs/content/documentation/webdriver/elements/locators.en.md[R85-86]

+  {{< tab header="CSharp" text=true >}}
+  {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs#L20-L21" >}}
Evidence
The driver is created at line 15 and element is declared at line 20, outside the new snippet
ranges. The old C# tabs contained var driver = new ChromeDriver() before their locator calls.

examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[15-42]
website_and_docs/content/documentation/webdriver/elements/locators.en.md[82-87]
website_and_docs/content/documentation/webdriver/elements/locators.en.md[112-117]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Individual C# documentation snippets omit the variables needed to compile them.
## Fix Focus Areas
- examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[15-42]
- website_and_docs/content/documentation/webdriver/elements/locators.en.md[85-286]
## Recommended Fix
Expose a driver declaration in each displayed example and declare the element within each independently displayed locator snippet; update the snippet ranges in all four languages.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


5. Two C# documentation tabs appear empty 🐞 Bug ≡ Correctness
Description
The ByChained and ByAll C# tabs replace badge-code with blank content in English and commented-out
shortcode calls in the three translated pages. Visitors selecting either tab see neither an example
nor the previous “Add Example” indicator; the commented ranges also point past the end of the
47-line source file.
Code

website_and_docs/content/documentation/webdriver/elements/locators.en.md[352]

+
Evidence
The changed English tab bodies contain no shortcode, and the corresponding translated bodies contain
only commented-out references. badge-code renders the missing-example badge removed by these
changes; LocatorsTest.cs ends at line 47.

website_and_docs/content/documentation/webdriver/elements/locators.en.md[349-380]
website_and_docs/content/documentation/webdriver/elements/locators.ja.md[350-378]
website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md[353-381]
website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md[353-381]
website_and_docs/layouts/shortcodes/badge-code.html[2-5]
examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs[41-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The ByChained and ByAll C# tabs no longer indicate that their examples are missing.
## Fix Focus Areas
- website_and_docs/content/documentation/webdriver/elements/locators.en.md[351-380]
- website_and_docs/content/documentation/webdriver/elements/locators.ja.md[350-378]
- website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md[353-381]
- website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md[353-381]
## Recommended Fix
Restore `badge-code` in both C# tabs across all four pages until working examples are available, and remove the commented references to nonexistent source lines.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Web pages:
  +2 more
Review mode: Auto: ⚖️ Balanced: Adds executable C# test logic and many documentation references requiring careful validation.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread website_and_docs/content/documentation/webdriver/elements/locators.en.md Outdated
Comment thread website_and_docs/content/documentation/webdriver/elements/locators.ja.md Outdated
Comment thread examples/dotnet/SeleniumDocs/Elements/LocatorsTest.cs
Comment thread website_and_docs/content/documentation/webdriver/elements/locators.en.md Outdated
Comment thread website_and_docs/content/documentation/webdriver/elements/locators.en.md Outdated

@diemol diemol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpallavisharma can you please check the Qodo comments?

namespace SeleniumDocs.Elements
{
[TestClass]
public class LocatorsTest : BaseTest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this tests become chrome specific. I am not sure whether we support matrix of browsers. Ig not, then it is OK.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually missed that. @rpallavisharma why do we need to avoid BaseTest?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason i avoid base test or inheritance or layers in any examples is, because i think examples should be standalone entity. Anyone can see them and understand what that command in selenium does and use it. People can have their own architecture.
And i checked the base test . cs file it shows chrome browser only.

Do we need to check if examples work for all browsers? why? im not sure here.

Let me know what you both think we should do with all example code being written across bindings.

i recall some historic conversation with Titus as well... not sure... now...
@diemol @nvborisenko @titusfortner

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpallavisharma yes, that is true but we need to do this in a separate effort.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i add basetest back then? let me know. i just don't like that approach :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quickly reviewed, .NET examples mix the approaches. So it is OK in this particular case to not inherit from base test.

@rpallavisharma

Copy link
Copy Markdown
Member Author

@rpallavisharma can you please check the Qodo comments?

yes i would look at what qodo says. @diemol

@rpallavisharma

Copy link
Copy Markdown
Member Author

the error -SeleniumDocs.BiDi.CDP.LoggingTest.ConsoleLogs still failing after 2 retries is not related to this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants