【发布时间】:2019-12-15 16:26:23
【问题描述】:
我在 selenium 中有一个小脚本来自动化一个网站。我还制作了一些函数来模拟鼠标移动,以生成大量模仿人类行为的鼠标移动,而不是从一个选择器跳到另一个选择器。我在新线程中运行它,但在第一次迭代后它抛出 selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds.
感谢帮助:)
类 facebook():
def __init__(self, login, password, counter=0):
self.login = login
self.password = password
self.browser = webdriver.Chrome("D:\selenium\chromedriver.exe")
self.browser.get("https://www.facebook.com/")
self.browser.set_window_size(1400,600)
self.action = ActionChains(self.browser)
self.thread()
def move_mouse(self):
actions = ActionChains(self.browser)
while True:
delay = random.uniform(0.1,0.3)
x = random.randint(400,900)
y = random.randint(100,400)
actions.move_by_offset(x,y).perform()
print("x:"+str(x)+" y:"+str(y))
time.sleep(2)
def thread(self):
newThread = threading.Thread(target=self.move_mouse, daemon=True)
newThread.start()
【问题讨论】: