docs: update docs to show role selectors (#18063)
This commit is contained in:
parent
ef8268fb89
commit
2efa96a882
|
|
@ -36,7 +36,7 @@ public class Tests : PageTest
|
|||
await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
|
||||
|
||||
// create a locator
|
||||
var getStarted = Page.Locator("text=Get Started");
|
||||
var getStarted = Page.GetByRole(AriaRole.Link, new() { NameString = "Get started" });
|
||||
|
||||
// Expect an attribute "to be strictly equal" to the value.
|
||||
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro");
|
||||
|
|
@ -71,7 +71,7 @@ public class UnitTest1 : PageTest
|
|||
await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
|
||||
|
||||
// create a locator
|
||||
var getStarted = Page.Locator("text=Get Started");
|
||||
var getStarted = Page.GetByRole(AriaRole.Link, new() { NameString = "Get started" });
|
||||
|
||||
// Expect an attribute "to be strictly equal" to the value.
|
||||
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro");
|
||||
|
|
@ -102,7 +102,7 @@ await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
|
|||
[Locators](./locators.md) are the central piece of Playwright's auto-waiting and retry-ability. Locators represent a way to find element(s) on the page at any moment and are used to perform actions on elements such as `.ClickAsync` `.FillAsync` etc. Custom locators can be created with the [`method: Page.locator`] method.
|
||||
|
||||
```csharp
|
||||
var getStarted = Page.Locator("text=Get Started");
|
||||
var getStarted = Page.GetByRole(AriaRole.Link, new() { NameString = "Get started" });
|
||||
|
||||
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/installation");
|
||||
await getStarted.ClickAsync();
|
||||
|
|
@ -111,7 +111,7 @@ await getStarted.ClickAsync();
|
|||
[Selectors](./selectors.md) are strings that are used to create Locators. Playwright supports many different selectors like [Text](./selectors.md#text-selector), [CSS](./selectors.md#css-selector), [XPath](./selectors.md#xpath-selectors) and many more. Learn more about available selectors and how to pick one in this [in-depth guide](./selectors.md).
|
||||
|
||||
```csharp
|
||||
await Expect(Page.Locator("text=Installation")).ToBeVisibleAsync();
|
||||
await Expect(Page.GetByRole(AriaRole.Heading, new() { NameString = "Installation" })).ToBeVisibleAsync();
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ test('homepage has Playwright in title and get started link linking to the intro
|
|||
await expect(page).toHaveTitle(/Playwright/);
|
||||
|
||||
// create a locator
|
||||
const getStarted = page.getByText('Get Started');
|
||||
const getStarted = page.getByRole('link', { name: 'Get started' });
|
||||
|
||||
// Expect an attribute "to be strictly equal" to the value.
|
||||
await expect(getStarted).toHaveAttribute('href', '/docs/intro');
|
||||
|
|
@ -51,7 +51,7 @@ test('homepage has Playwright in title and get started link linking to the intro
|
|||
await expect(page).toHaveTitle(/Playwright/);
|
||||
|
||||
// create a locator
|
||||
const getStarted = page.getByText('Get Started');
|
||||
const getStarted = page.getByRole('link', { name: 'Get started' });
|
||||
|
||||
// Expect an attribute "to be strictly equal" to the value.
|
||||
await expect(getStarted).toHaveAttribute('href', '/docs/intro');
|
||||
|
|
@ -82,7 +82,7 @@ await expect(page).toHaveTitle(/Playwright/);
|
|||
[Locators](./locators.md) are the central piece of Playwright's auto-waiting and retry-ability. Locators represent a way to find element(s) on the page at any moment and are used to perform actions on elements such as `.click` `.fill` etc. Custom locators can be created with the [`method: Page.locator`] method.
|
||||
|
||||
```js
|
||||
const getStarted = page.getByText('Get Started');
|
||||
const getStarted = page.getByRole('link', { name: 'Get started' });
|
||||
|
||||
await expect(getStarted).toHaveAttribute('href', '/docs/installation');
|
||||
await getStarted.click();
|
||||
|
|
@ -92,7 +92,7 @@ await getStarted.click();
|
|||
|
||||
|
||||
```js
|
||||
await expect(page.getByText('Installation')).toBeVisible();
|
||||
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ def test_homepage_has_Playwright_in_title_and_get_started_link_linking_to_the_in
|
|||
expect(page).to_have_title(re.compile("Playwright"))
|
||||
|
||||
# create a locator
|
||||
get_started = page.locator("text=Get Started")
|
||||
get_started = page.get_by_role("link", name="Get started");
|
||||
|
||||
# Expect an attribute "to be strictly equal" to the value.
|
||||
expect(get_started).to_have_attribute("href", "/docs/intro")
|
||||
|
|
@ -51,7 +51,7 @@ expect(page).to_have_title(re.compile("Playwright"))
|
|||
```python
|
||||
from playwright.sync_api import expect
|
||||
|
||||
get_started = page.locator("text=Get Started")
|
||||
get_started = page.get_by_role("link", name="Get started");
|
||||
|
||||
expect(get_started).to_have_attribute("href", "/docs/installation")
|
||||
get_started.click()
|
||||
|
|
@ -63,7 +63,7 @@ get_started.click()
|
|||
```python
|
||||
from playwright.sync_api import expect
|
||||
|
||||
expect(page.locator("text=Installation")).to_be_visible()
|
||||
expect(page.get_by_role("heading", name="Installation")).to_be_visible()
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue