如何在Python中使用seleniumbase在nav元素中滚动

问题描述 投票:0回答:1
<nav class="flex h-full w-full flex-col p-2 gizmo:px-3 gizmo:pb-3.5 gizmo:pt-0" aria-label="Menu">

这是导航,它更长,充满了div

我只想知道如何滚动到菜单末尾。 编辑: 加载必须考虑的元素

<svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" class="animate-spin text-center" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">

在它的下面有很多线条元素

导航 xpath 顶部:

/html/body/div[1]/div[1]/div[1]/div/div/div/div/nav

svg xpath 顶部:

/html/body/div[1]/div[1]/div[1]/div/div/div/div/nav/div[2]/div[2]/div[2]/svg
python html scroll seleniumbase
1个回答
0
投票

要在Python中使用SeleniumBase滚动导航元素,您可以使用execute_script方法来运行将元素滚动到视图中的JavaScript代码。这是一个例子:

from seleniumbase import BaseCase
    
    class MyTestClass(BaseCase):
        def test_scroll_to_end_of_menu(self):
            # Assuming driver is your Selenium WebDriver instance
            # Replace 'your_website_url' with the actual URL of the page containing the nav element
    
            # Open the website
            self.open("your_website_url")
    
            # Locate the nav element
            nav_element = self.driver.find_element_by_css_selector("nav.flex")
    
            # Scroll to the end of the menu using JavaScript
            self.driver.execute_script("arguments[0].scrollIntoView(false);", nav_element)
© www.soinside.com 2019 - 2024. All rights reserved.