Comments (7)
Its possible! You can set force=True
:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
page.goto('https://codepen.io/kanpeki/pen/RLboWN')
my_checkbox = page.frame_locator("iframe[name='CodePen']").locator("[id='slideThree']")
my_checkbox.highlight()
my_checkbox.set_checked(True, force=True)
browser.close()
See here: https://playwright.dev/docs/actionability#forcing-actions
from playwright-python.
I tried the following which works for me:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto('http://example.com')
page.set_content("""
<label class="ui-switch">
<input type="checkbox" id=":chb" tabindex="0" class="form-control">
<span class="slider round">
<div>
::before
</div>
</span>
</label>
""")
my_checkbox = page.locator("[id=':chb']")
my_checkbox.set_checked(False)
browser.close()
from playwright-python.
Thank you Max, yes, this is strange... when setting the content it's working.
But when I'm using my live page, it doesn't...
Do you have any idea how could I debugging the root cause?
My slider is visible, enabled and nothing blocks it on the page... could that be a javascript (onchange event) related issue?
When adding .highlight() I can see the element has found... but the set_checked cannot be executed
from playwright-python.
Here is another example with the bug, please execute and check the results:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto('https://codepen.io/kanpeki/pen/RLboWN')
my_checkbox = page.frame_locator("iframe[name='CodePen']").locator("[id='slideThree']")
my_checkbox.highlight()
my_checkbox.set_checked(True)
browser.close()
from playwright-python.
Have you tried using Codegen to generate a locator? A user does not click in this scenario on the input
element itself, the user instead clicks on the label. The input
element itself is not visible in this case. So you can do something like this (generated by Codegen):
import re
from playwright.sync_api import Playwright, sync_playwright, expect
def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("https://codepen.io/kanpeki/pen/RLboWN")
page.frame_locator("iframe[name=\"CodePen\"]").get_by_title("Slide 3").locator("label").click()
# ---------------------
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)
from playwright-python.
I would say, the fact that set_checked() cannot be used on hidden (or display: none) input, is an unexpected limitation.
Is it possible to remove the verification of the element visibility from playwright?
As you can see, we have scenarios like this, when input field is not visible but would like to control over the set_checked()
from playwright-python.
Thank you!
from playwright-python.
Related Issues (20)
- How to get the error type Console in the browser? HOT 3
- How to locate the chromewebstore's confirm dialog? HOT 1
- how to get Twitter cookie and login with headless chromium HOT 1
- [Bug]: `Download.failure()` raises `TypeError: expected string or bytes-like object, got 'NoneType'`
- [Bug]: Error: net::ERR_PROXY_CONNECTION_FAILED .... is of type playwright._impl._errors.Error HOT 1
- [Bug]: Future finished exception=TargetClosedError('Target page, context or browser has been closed')
- [Bug]: Using playwright browser to measure the FCP & LCP caused inaccuracy HOT 1
- [Feature]: allow reuse of JavaScript functions HOT 1
- What is the value list for local in Playwright? HOT 1
- [Bug]: use async api with threading moudle cause process hang forever HOT 2
- When I open the browser using playwright.chromium. launch_persistent_context, I use page. go to open a URL for example https://111.html To manually open a URL for the tag page https://222.html The tag page does not have a URL when calling context. pages https://222.html What is the reason for the page, and how can I obtain the second page? HOT 1
- [Question]The content.pages method cannot retrieve all pages HOT 2
- [Bug]: Apple App store link is not opening in a new tab while clicking a link [mobile: iPhone 13] HOT 1
- [Bug]: proxy not connect HOT 1
- [Bug]: In mac sonoma, browser the installed version and the using version are missmatching. HOT 1
- [Bug]: Running with the synchronization method reports an error HOT 2
- [Bug]: Getting node:events:492 write EPIPE error HOT 3
- [Ports]: Backport client side changes for 1.45
- [Bug]: Images do not print when performing print-to-pdf HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright-python.