Python 我想用ActionChains点击网页的随机部分
就像问题中提到的,我想点击网页上完全随机的部分 这是我当前使用Python 3编写的脚本:Python 我想用ActionChains点击网页的随机部分,python,python-3.x,selenium,Python,Python 3.x,Selenium,就像问题中提到的,我想点击网页上完全随机的部分 这是我当前使用Python 3编写的脚本: while int(seconds) > 0: try: x = random.randint(10, 1200) y = random.randint(100, 800) #Clicks random part of the page upperleft.move_to_element_with_offset(element,
while int(seconds) > 0:
try:
x = random.randint(10, 1200)
y = random.randint(100, 800)
#Clicks random part of the page
upperleft.move_to_element_with_offset(element, x, y)
upperleft.click()
upperleft.perform()
time.sleep(0.1)
seconds = seconds - 1
back = back + 1
except Exception as e:
print(e)
time.sleep(0.1)
seconds = seconds - 1
back = back + 1
元素是页面左上角的元素。
我知道这个脚本有时什么都不点击。但是,我总是收到以下错误消息:
陈旧元素引用:元素未附加到页面文档
这是我的窗口大小:
chrome_options.add_argument("window-size=1280,900")
我做错了什么
添加:
element = driver.find_element_by_xpath('//*[@class="back-to-nike-link d-sm-ib va-sm-m pt2-sm pb2-sm prl7-sm d-sm-ib"]')
这是nike.com/launch左上角的元素。这是因为有时候Selenium找不到任何可点击的内容。是的,脚本有时什么都不点击,这对我来说不是什么大问题。在“元素”中有什么元素,变量左上角的变量是什么将其添加到主要问题中。对不起,我应该想到这个。