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

⬇️ Test to make sure hidden dropdown elements are not being tagged #141

Merged
merged 9 commits into from
Aug 29, 2024
17 changes: 17 additions & 0 deletions tests/mock_html/dropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<label>
<select style="font-size: xx-large">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
<option value="option4">Option 4</option>
</select>
</label>
</body>
</html>
31 changes: 30 additions & 1 deletion tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,19 @@
IS_GITHUB_ACTIONS, reason="Skipping language test in CI"
),
),
(
"mock_html/dropdown.html",
{
0: "//html/body/label",
},
["Option 1"],
["[ $ 0 ]"],
),
(
"mock_html/iframe.html",
{0: "iframe[0]//html/body/p"},
{
0: "iframe[0]//html/body/p",
},
["This is some text content inside the iframe"],
["[ 0 ]"],
),
Expand Down Expand Up @@ -198,3 +208,22 @@ async def test_text_nodes_are_query_selectable(async_page):
assert len(tag_to_xpath) == 2
assert await async_page.query_selector(tag_to_xpath[0])
assert await async_page.query_selector(tag_to_xpath[1])


@pytest.mark.asyncio
async def test_dropdown_text_not_shown(tarsier, async_page):
dropdown_html_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "mock_html/dropdown.html")
)
await async_page.goto(f"file://{dropdown_html_path}")
page_text, tag_to_xpath = await tarsier.page_to_text(
async_page, tag_text_elements=True
)

assert "[ $ 1 ]" not in page_text
assert "[ $ 2 ]" not in page_text
assert "[ $ 3 ]" not in page_text
assert "[ $ 4 ]" not in page_text
assert "Option 2" not in page_text
assert "Option 3" not in page_text
assert "Option 4" not in page_text