硒发现元素VBA阻止例程 [英] selenium findelement vba blocks the routine

查看:98
本文介绍了硒发现元素VBA阻止例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我打开网站并搜索对象的代码。可能会发生找不到对象的情况,因此我必须对它的存在进行设置搜索,以便执行或不执行操作。我正在尝试这种方式,但是如果我要查找的对象会导致例程崩溃...。

  Dim bot As新的SeleniumWrapper.WebDriver 
bot.SetProfile C:\Users\USER\AppData\Local\Google\Chrome\UserData\Default
bot.start chrome , https://website.com/
bot。打开 /
bot.wait 10000
bot.findElementByClassName( _ 20NlL)。点击
bot。等待1000
bot.findElementByClassName( C28xL)。单击
机器人。等待1200
bot.SendKeys文本
机器人。等待2000
将Dim notext用作WebElement
设置notext = bot.findElementByClassName( _ 3WZoe,timeoutms:= 0)
如果notext不存在,则
...... [这是显示给我的错误] [1]

![1]: https://i.stack.imgur.com/wWKzW.jpg



我怎么了? ?



如果我按照QHarr的说明将bot声明为webdriver或chromedriver,则会收到此错误消息或不幸的是...。



错误运行时33:会话未创建异常ecc。我使用的是chrome 69.0

解决方案

我看到的许多错误使我认为您已将其翻译为另一种语言,或使用的语法不适用于当前硒基本包装器



1)对于基本硒,以下 timeoutms 不是命名参数。正确的命名参数是 timeout ,因此您报告的错误有些奇怪,因为您应该已经收到命名参数错误消息。



2)如果使用Chrome,只需声明为 Dim bot as New WebDriver New ChromeDriver

3)使用硒基础的正确方法是 FindElementByClass






您的 sendKeys 应该重点放在特定元素上,例如

  bot.findElementByClass( C28xL)。SendKeys文本






您可以检查元素当前是否存在

  bot.findElementByClass( _ 3WZoe ,timeout:= 0,Raise:= False)

同样,请牢记导航父母的要点表单/框架/ iframe 标签和等待时间。






确保您正在使用最新的Chrome浏览器和 ChromeDriver 。 ChromeDriver应该位于环境路径,即位于环境路径中的文件夹中,并且路径部分(对于驱动程序)应为(但不包括).exe(但不包括.exe)(即,包含文件夹的级别)。您也可以在代码中以语句的形式指定查找驱动程序的位置。


this is my code to open a site and search for objects. It may happen that an object is not found and therefore I have to set up a search on its existence or not, so as to perform or not operations. I'm trying this way but if the object I'm looking for, the routine crashes ....

  Dim bot As New SeleniumWrapper.WebDriver
  bot.SetProfile "C:\Users\USER\AppData\Local\Google\Chrome\User Data\Default"
  bot.start "chrome", "https://website.com/"
  bot.Open "/"
  bot.wait 10000
  bot.findElementByClassName("_20NlL").Click
  bot.Wait 1000
  bot.findElementByClassName("C28xL").Click
  bot.Wait 1200
  bot.SendKeys text
  bot.Wait 2000
  Dim notext As WebElement
  Set notext = bot.findElementByClassName("_3WZoe", timeoutms:=0)
  If notext Is Nothing Then
  ......[this is the error that is shown to me][1]

![1]: https://i.stack.imgur.com/wWKzW.jpg

what am I wrong?

if I declare bot as webdriver or chromedriver as indicated by QHarr I get this error unfortunately ....

error run-time 33: session not created exception ecc. i'm using chrome 69.0

解决方案

A number of the errors I can see make me think you have translated this across from another language, or are working with syntax not designed for current selenium basic wrapper.

1) For selenium basic the following timeoutms is not a named argument. The correct named argument is timeout so something is odd with your reported error as you should have received a named argument error message.

2) Simply declare as Dim bot As New WebDriver or New ChromeDriver if using Chrome.

3) The correct method with selenium basic is FindElementByClass


Your sendKeys likely should be focused on a specific element e.g.

bot.findElementByClass("C28xL").SendKeys Text


You can check whether an element is currently present with

bot.findElementByClass("_3WZoe", timeout:=0, Raise:=False)

Again, bearing in mind the point around navigating parent form/frame/iframe tags and wait times.


Ensure you are using the latest Chrome browser and ChromeDriver. The ChromeDriver should be on the environmental path i.e. in a folder which is on the enviromental path and that the path section (for the driver) should be up to, but not including, the .exe (i.e. to the containing folder level). You can alternatively specify the location to look in for the driver as a statement within the code.

这篇关于硒发现元素VBA阻止例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆