Conseguiu entrar no formulario e datepicker
This commit is contained in:
59
test_datepicker.py
Normal file
59
test_datepicker.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
import os
|
||||
|
||||
html_content = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<input type="text" class="datepicker1" id="dp1">
|
||||
<input type="text" class="datepicker2" id="dp2">
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
|
||||
<script>
|
||||
$('.datepicker1').datepicker();
|
||||
$('.datepicker2').datepicker();
|
||||
// open the first one
|
||||
$('.datepicker1').datepicker('show');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
async def test_date():
|
||||
with open("test.html", "w") as f:
|
||||
f.write(html_content)
|
||||
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
page = await browser.new_page()
|
||||
await page.goto(f"file://{os.path.abspath('test.html')}")
|
||||
|
||||
day = 15
|
||||
|
||||
# Original logic
|
||||
try:
|
||||
dp = page.locator(".datepicker-days")
|
||||
await dp.wait_for(state="visible", timeout=5000)
|
||||
|
||||
cells = dp.locator("td.day:not(.old):not(.new)")
|
||||
count = await cells.count()
|
||||
print(f"Total cells found: {count}")
|
||||
for i in range(count):
|
||||
text = (await cells.nth(i).inner_text()).strip()
|
||||
if text == str(day):
|
||||
print(f"Trying to click cell {i} with text {text}")
|
||||
await cells.nth(i).click(timeout=1000)
|
||||
print(f"📅 Dia {day} selecionado.")
|
||||
return
|
||||
except Exception as e:
|
||||
print(f"ERROR: {type(e).__name__}: {str(e)}")
|
||||
|
||||
await browser.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_date())
|
||||
Reference in New Issue
Block a user