我目前正在编写一个脚本,自动完成游戏little alchemy 2。在
随着游戏的进行,已经发现的物品库会不断增加,最终你必须滚动到一些较低的物品。
当我尝试获取的项目不在屏幕上时,Selenium抛出异常MoveTargetOutOfBoundsException
。在
我尝试通过捕捉异常并使用move_to_element
将该项带到Selenium的范围内来解决这个问题。但当我试了一下,什么也没发生。有什么想法吗?在
try:
ActionChains(driver).drag_and_drop(elempic2, workspace).perform()
except MoveTargetOutOfBoundsException:
print ("Need to Scroll because if element 2")
ActionChains(driver).move_to_element(elempic2).perform()
ActionChains(driver).drag_and_drop(elempic2, workspace).perform()
print ("Element 2 dragged: " + str(elemname2.text))
引发的错误:
^{pr2}$如果你想自己试一试,here就是回购。在
感谢您的帮助:)
我会将滚动逻辑转换为不需要目标元素在视图中的内容,例如:
这只是使用JavaScript向下滚动页面,直到可以执行工作为止。在
相关问题 更多 >
编程相关推荐