I have a web page with several components and one of its components is a panel (with a scroll bar) consists of 20 options in total, as given below:
When the web page loads, only first 7 options are visible, but I need to check the check box of 15th option. So I might need to scroll inside that panel.
Below can be considered as a sample code replicates the similar scenario:
url = "https://www.htmlelements.com/demos/dropdownlist/checkboxes/"
locator_dropdown = "//span[@class='smart-token']"
locator_option = "//smart-list-item[@label='Galao']"
with sync_playwright() as p:
browser = p.chromium.launch(headless=False) # 1.Launch the browser
page = browser.new_page() # 2. Load the web page
page.goto(url) # 3. Go to given URL
page.locator(locator_dropdown).click() # 4. Click on dropdown
page.locator(locator_option).check() # 5. Check 15th option
The 'locator_option' in step #5 is the locator of checkbox of 15th option inside the dropdown. But it fails to locate the element, since only 10 options are visible when page loads and 15th option is not visible unless scroll inside the dropdown panel.
I would like to know if there is a method to check the checkbox of a particular option which is not visible unless we scroll inside the dropdown. One way is to click on the up and down arrow on the scroll bar to control the same. But it would be efficient if there is any other way to scroll to a specific element inside the a web element.
I really appreciate if someone can explain how to scroll inside a web element like this until a specific value/ element is visible, using playwright python.
Note: I am trying to scroll inside a web element, and not to scroll the webpage. The example given above is just a sample page with a dropdown list with checkboxes, because I could not get any other sample websites having a panel with list of options along with checkboxes for each option.
locator_optionisn't defined. Please share your full code.