Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Javascript Executor Click()在实际单击页面之前搜索页面上的元素_Javascript_Python_Html_Selenium_Web - Fatal编程技术网

Selenium Javascript Executor Click()在实际单击页面之前搜索页面上的元素

Selenium Javascript Executor Click()在实际单击页面之前搜索页面上的元素,javascript,python,html,selenium,web,Javascript,Python,Html,Selenium,Web,我正在使用Selenium自动化一个网站,但是click()不起作用。它返回一个无法滚动到视图中的元素 我使用Javascript Executor调用click(),编写代码是为了在单击()后在页面上查找单击的元素。然而,Selenium试图在点击网站之前找到元素 我在脚本运行时查看了网站,它试图找到元素,然后单击它所在的页面。我该如何解决这个问题 (代码如下) 我已经尝试过使用WebDriver等待该元素可单击。但是,它每次都会超时,所以我没有想法。感谢您的帮助 Find_Section

我正在使用Selenium自动化一个网站,但是
click()
不起作用。它返回一个无法滚动到视图中的元素

我使用Javascript Executor调用
click()
,编写代码是为了在单击()后在页面上查找单击的元素。然而,Selenium试图在点击网站之前找到元素

我在脚本运行时查看了网站,它试图找到元素,然后单击它所在的页面。我该如何解决这个问题

(代码如下)

我已经尝试过使用WebDriver等待该元素可单击。但是,它每次都会超时,所以我没有想法。感谢您的帮助

  Find_Section = Driver.find_element_by_xpath('//div[contains(text()="Text"]')
  Driver.execute_script("arguments[0].click();", Find_Section)
  Tester = Driver.find_element_by_partial_link_text('Test19')
  Tester.click()
编辑:

我相信我已经根据调查结果找出了问题所在 click()的行为与实际用户的行为类似,execute_脚本没有,只是调用了事件,因此我认为execute_脚本正在单击事件,但没有执行与click()相同的操作,因此无法正确加载页面

我之所以使用execute_脚本,是因为click()方法每次都会抛出cannotscroll元素到视图中


我可能错误地理解了我认为它不起作用的原因,如果这样请更正我

我终于弄明白了,因为这里没有人会帮助我,因为有人感兴趣。例如,您需要在下一个元素之前插入等待语句

try:
    time.sleep(2) # Could be WebDriverWait
    Find_Example = driver.find_element_by_partial_link_text('Example')
    time.sleep(2) # Try to make bot less noticeable 
    Find_Example.click()
except InvalidElement: # Defined in the import section
   # Syntax may be wrong i wrote this by hand in this little text window
   print("\033[31m Could Not Find The Desired Element [STATUS] \033[31m")
   exit()