python - Selecting incorrect submenu item after hover action -
i'm developing test case in python webdriver click through menu items on http://www.ym.com, , particular 1 meant go through menu item , click on sub-menu item.
when running test, looks tries access nested menu items, never clicks on final item. here code go through menu:
food = driver.find_element_by_id("menu-item-1654") hov = actionchains(driver).move_to_element(food).move_to_element(driver.find_element_by_xpath("/html/body/div[4]/div/div/ul/li[2]/ul/li/a")).click() hov.perform()
the problem here trying click "recipes" submenu "food" menu, happens submenu "france" being clicked under menu "travel" situated right next "recipes.
i've tried using find_element_by_id, find_element_by_css_locator, find_element_by_link_text seems select france submenu under travel , not recipes submenu under food.
any ideas?
edit
i using python code run test now:
food = driver.find_element_by_xpath("//a[contains(@href, 'category/food/')]/..") actionchains(driver).move_to_element(food).perform() webdriverwait(driver, 5).until(lambda driver: driver.find_element_by_xpath("//a[contains(@href, 'category/recipes-2/')]/..")).click()
which works fine in ie, still access wrong menu item in firefox.
try use normal click instead of actionchains' move , click.
changes code:
- i assume ids dynamic, try avoid using them.
- try avoid using absolute xpath
- use normal click rather actionchain move , click
- use 5 seconds webdriverwait recipes link.
food = driver.find_element_by_xpath("//a[contains(@href, 'category/food/')]/..") hov = actionchains(driver).move_to_element(food).move_by_offset(5, 45).perform() # 45 height of 'food' link plus 5 recipes = webdriverwait(driver, 5).until(lambda driver: driver.find_element_by_xpath("//a[contains(@href, 'category/recipes-2/')]/..")) recipes.click()
a tested working c# version of code:
driver.navigate().gotourl("http://www.yumandyummer.com"); iwebelement food = driver.findelement(by.xpath("//a[contains(@href, 'category/food/')]/..")); new actions(driver).movetoelement(food).movebyoffset(5, food.size.height + 5).perform(); webdriverwait wait = new webdriverwait(driver, timespan.fromseconds(5)); iwebelement recipes = wait.until(expectedconditions.elementexists(by.xpath("//a[contains(@href, 'category/recipes-2/')]/.."))); recipes.click();
Comments
Post a Comment