如何浏览网站,将鼠标悬停在子菜单上,然后使用selenium python单击一个网站

时间:2018-05-01 05:53:20

标签: javascript python-3.x selenium

我试图自动化我的一个网络应用程序" maximo"通过使用selenium python。 我可以使用用户名和密码登录,也可以使用" find_element_by _"等单击任何一个按钮。但我不知道如何将鼠标悬停在子菜单上并单击。

此外,我试图找到一种方法来调用与菜单相对应的Javascript代码,这些代码显示在此maximo的底部(附图片)。 enter image description here

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

browserchr3=webdriver.Chrome('C:\chromedriver\chromedriver.exe')
browserchr3.get('http://da-maximo.dca.com/maximo/webclient/login/login.jsp?welcome=true')
browserchr3.find_element_by_id('username').send_keys('bhsek015'+Keys.TAB)

userpassword=browserchr3.find_element_by_id('password')
userpassword
userpassword.send_keys('Adil@2020')
userpassword.submit()
#browserchr3.execute_script(topLevelMenus['m7f8f3e49_ns_mc'].menuClick({"id":"WOTRACK_APP","text":"Work Order Tracking","eventvalue":"WOTRACK","apptype":"RUN","target":"startcntr","event":"changeapp","value":"WOTRACK"}))
browserchr3.implicitly_wait(10)                      

Select(browserchr3.find_element_by_css_selector('#m7f8f3e49_ns_menu_WO_MODULE_a')).select_by_visible_text("Work Order Tracking")
wo
wo.click()
browserchr3.implicitly_wait(10)
wot=browserchr3.find_element_by_css_selector('#menuholdertd')
wot
wot.click()

1 个答案:

答案 0 :(得分:0)

对于您的问题1,将鼠标悬停在元素上,您需要使用Action Chains

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(browserchr3)
# Assuming wot is the element to move your mouse to
actions.move_to_element(wot)
actions.perform()    #Performs chained action

你可以链接这样的动作     ActionChains(browserchr3).move_to_element(WOT).perform()

如需完整参考,请查看API => https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html

问题2,如何执行javascript,

browserchr3.execute_script('Script statement')