Selenium:将鼠标移动到元素不起作用

时间:2016-04-18 23:00:03

标签: python selenium element move mousemove

我试图在弹出窗口中占用时间,只有当我将鼠标光标移动到弹出窗口时才出现。然后将鼠标移动到另一个点。我在osx和ubuntu上尝试使用firefox和phantomjs。 Phantomjs永远不会工作,Firefox有时可以工作,有时它不工作,有时移动元素工作,movebyoffset不工作。我也尝试了等待和睡眠功能,结果相同。 Page是ajax内容。当我尝试单击“href = javascript”按钮时,我遇到了同样的问题。可能是什么问题?

movetoelement=css(".content")
action = webdriver.ActionChains(browser)
action.move_to_element(movetoelement)
action.perform()
time = css('.time').text
print time
actionoffset = webdriver.ActionChains(browser)
actionoffset.move_by_offset(10,10)
actionoffset.perform()

它需要登录,所以我可以告诉你html。我的css路径没有问题。正如我所说,有时候它会起作用,有时则不然。

> This is for the element to hover on.
> 
> <a class="tLink event ajaxify" href=“url"
> ajaxtarget="mainLeftContent”>contentbody</a>
> 
> This is for the button
> 
> <a id=“pressbutton" class="tButton large blue" href="javascript:"
> onclick="xcoupon.fn.openPreview()" bt-xtitle="" title=“">Continue</a>

1 个答案:

答案 0 :(得分:0)

你有没有试过链接你的行为?

movetoelement=css(".content")
action = webdriver.ActionChains(browser)
actionoffset = webdriver.ActionChains(browser)   
action.move_to_element(movetoelement).actionoffset.move_by_offset(10,10).perform()

请注意,在浏览器窗口中移动鼠标往往会破坏这样的测试。