他们有很多问题,关于Move_to_element无法正常工作,我尝试了一切,但没有成功。
我也没有得到任何错误。请帮我解决这个问题
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>
Locations.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文件中调用。
Finaltest.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()
帮我解决这个问题
答案 0 :(得分:3)
最重要的是,您没有执行动作链:
ActionChains(driver).move_to_element(men_menu).click(men_menu).perform()
# ^^^^^^^^^