1

Their are Lot of Questions For Move_to_element is not working i tried everything but not working.

Am not Getting any error also. Please help me to Figure me this out

HTML Code :

<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)

Am using pageobject model concept this file will be called in a seperate python file.

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()

Help me to figure this out

koushick
  • 497
  • 2
  • 8
  • 30

1 Answers1

4

The most important thing, you are not performing the action chain:

ActionChains(driver).move_to_element(men_menu).click(men_menu).perform()
#                                                              ^^^^^^^^^
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Major Mistake, Now Corrected it Thanks . But First When i Used Perform() Without Clicking , it didn't Work. But now after clicking i used perform(), it worked. Thanks @alecxe – koushick Dec 14 '18 at 14:46
  • May i know why it didn't work when i used only perform()?any suggesstions? – koushick Dec 14 '18 at 14:48
  • 1
    @koushick hard to say without actually trying it out, it could be that you needed to mouse move some other element first and then move to the desired one. Or, it's an implementation detail of this UI element. Glad you solved it, thanks. – alecxe Dec 14 '18 at 14:49
  • @koushick btw, created this as a follow-up as I keep seeing this problem https://stackoverflow.com/questions/53782016/missing-perform-for-selenium-actionchains. – alecxe Dec 14 '18 at 15:18
  • in java we no need click() method to mouse over some element. but in python we are in need of it. am also gathering information everywhere but no perfect solution glad you sorted out for me to run my program.Thanks! – koushick Dec 14 '18 at 18:36