在python中找不到Mouseover move \u to \u元素

2024-06-24 12:57:37 发布

您现在位置:Python中文网/ 问答频道 /正文

他们有很多问题,移动到元素不工作,我尝试了一切,但没有工作

我没有得到任何错误也。请帮我把这个弄清楚

HTML代码:

<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" id="second_dropdown" css="1" style="">Our Locations
    <span class="caret"></span>
</a>

位置。py:

import  time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Locationspage():

    def __init__(self,driver):
        self.driver = driver

    def All_Locations(self):
        self.Move_to_Loc(self.driver)

    def Move_to_Loc(self,driver):
        men_menu = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#second_dropdown")))
        time.sleep(5)
        ActionChains(driver).move_to_element(men_menu).click(men_menu)

我使用pageobject模型概念这个文件将在一个单独的python文件中调用

最终测试.py

import unittest
from selenium import webdriver
from TestMethods.index import Wepaythemaxindex
from TestMethods.Locations import Locationspage
import time

class Wepaythemax(unittest.TestCase):
    def setUp(self):
        self.driverchrome = webdriver.Chrome("F:\\New folder\\chromedriver.exe")


    def test_Pages(self):
        driver = self.driverchrome
        driver.maximize_window()
        driver.get("http://xxx.xxx.x.xxx:xxxx/")
        driver.implicitly_wait(10)
        for text_node in driver.find_elements_by_css_selector('.cd-words-wrapper > b'):
            print(text_node.get_attribute('textContent'))

        #index Page ----
        #index = Wepaythemaxindex(driver)
        #index.checkchromedriver()

        #Locations_Page
        Location = Locationspage(driver)
        Location.All_Locations()





    def tearDown(self):
        self.driverchrome.quit()

if __name__ == '__main__':
    unittest.main()

帮我弄清楚


Tags: tofromimportselfindextimedefdriver