GVKun编程网logo

使用VBA和Selenium来驱动网站(vba任务驱动教程)

17

本文的目的是介绍使用VBA和Selenium来驱动网站的详细情况,特别关注vba任务驱动教程的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解使用VBA和Seleniu

本文的目的是介绍使用VBA和Selenium来驱动网站的详细情况,特别关注vba任务驱动教程的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解使用VBA和Selenium来驱动网站的机会,同时也不会遗漏关于Android-使用Appium和Selenium网格进行并行测试、c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、Docker,Django和Selenium-Selenium无法连接、Excel vba selenium - 单击坐标的知识。

本文目录一览:

使用VBA和Selenium来驱动网站(vba任务驱动教程)

使用VBA和Selenium来驱动网站(vba任务驱动教程)

我必须登录SnapSurveys并每月下载20多个文件。现在已经是一个繁琐的过程,现在我必须每周执行一次,而手工完成将变得很繁琐,所以我想实现它的自动化并安装了Selenium来做到这一点。我已经使用SeleniumIDE(在FireFox中)跟踪了整个过程,所以我知道我想做的事情以及如何做的基础知识,但是,我遇到了一个难以理解的砖墙,试图理解该网页。实现它的结构。

使用Chrome和FireFox中的开发工具,我已将“用户名”字段标识为:

<p>    <label for="UserName">Username</label>    <input data-val="true" data-val-required="The Username field is required." id="UserName" name="UserName" type="text" value="">    <spandata-valmsg-for="UserName" data-valmsg-replace="true"></span></p>

我正在使用以下代码来尝试查找“用户名”文本框,以便在其中键入数据。我Text依次尝试了每种的值和每种Driver.FindElementBy...可能性,它们都给了我这个错误:

Run-time Error ''7'':NoSuchElementErrorElement not found for <By type> = <text>

这是代码:

Private Sub Login()  Const SITE_BASE_NAME As String = "https://www.snapsurveys.com/login"  Dim Driver As IEDriver  Set Driver = New IEDriver  Dim IsSiteLoaded As Boolean  IsSiteLoaded = Driver.Get(SITE_BASE_NAME)  If IsSiteLoaded Then    Dim Text As String    Text = "columns six"    Text = "UserName"    Text = "main"    Text = "//*[@id=""UserName""]"    Dim El As WebElement    Set El = Driver.FindElementByClass(Text)    Set El = Driver.FindElementByCss(Text)    Set El = Driver.FindElementById(Text)    Set El = Driver.FindElementByLinkText(Text)    Set El = Driver.FindElementByName(Text)    Set El = Driver.FindElementByPartialLinkText(Text)    Set El = Driver.FindElementByTag(Text)    Set El = Driver.FindElementByXPath(Text)  End If  Driver.QuitEnd Sub

我发现 没有 给我一个错误的一个组合是:

Text = "main"Set El = Driver.FindElementById(Text)

但这仅使我成为屏幕顶部的面包屑,而且我不确定如何从那里获得有用的信息。

显然,我对Web设计的了解不足,无法提供我应该寻找的任何线索,但是我认为我可以通过尝试和错误尝试来解决此问题,而这比这要少得多。

我需要在页面源代码中寻找哪些元素,FindElementBy需要使用哪些函数在代码中进行搜索?

此外,是否填写用户名和密码字段,单击“登录”,然后单击下一页上的相应链接等,是实现此目的的最佳方法吗?我 认为
登录后,应该可以为我需要的每个文件获取一个链接集合,然后直接下载每个链接,但是我不确定是否可以做到这一点。

一些注意事项:

  • 是的,我意识到该代码正在使用IE作为浏览器。我为FF和Chrome安装的驱动程序似乎已经过时(浏览器会打开,但不会加载网页),而且我还没有更新的驱动程序。目前,只要能正常使用,我都不会在乎使用哪种浏览器。
  • 是的,我意识到我要在末尾关闭浏览器Sub。同样,我只是在测试,试图在黑暗中找到自己的路。

答案1

小编典典

登录功能位于中iframe。您必须将硒的焦点切换到该iframe,然后再试一次,它应该可以工作。

您可以尝试以下方法:

Driver.switchtoframe (0)Driver.FindElementById("UserName")

有关Web设计的一些知识在处理硒自动化方面可以有很长的路要走,但是只要具备一些基本知识,您就可以轻松完成工作。

您应该寻找什么元素取决于您要实现的目标。如果要在文本字段中输入内容,则应查找<inputtype="text">元素,对于表格,则需要查找<table>元素。

我通常更喜欢通过xpath使用find元素,但是如果该元素具有唯一性idclass在网页上,则可以按类名使用find元素,也可以按id使用find元素。

您似乎在正确的道路上可以自动执行任务。

Android-使用Appium和Selenium网格进行并行测试

Android-使用Appium和Selenium网格进行并行测试

我正在尝试使用appium&在2个设备上运行并行测试.硒网格,但由于某种原因,它仅在第一台节点服务器(和第一台设备)上运行,而在第二台服务器上什么也没有发生.

另外,如果我关闭第一台服务器并运行测试,那么该测试将在第二台服务器上运行,因此服务器应该没有任何问题.

是否必须提供一些参数才能将其设置为parallel?

谢谢您的帮助 !

这是我的文件:

第一个服务器json文件:

{
  "capabilities":
  [
    {
      "browserName": "SamsungS6",
      "deviceName": "04157df40862d02f",
      "version":"6.0.1",
      "maxInstances": 3,
      "platform":"ANDROID"
    }
  ],
  "configuration":
  {
    "cleanUpCycle":2000,
    "timeout":30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url":"http://localhost:4491/wd/hub",
    "host": "localhost",
    "port": 4491,
    "maxSession": 5,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4433,
    "hubHost": "localhost"
   }
}

第二个服务器json文件:

{
  "capabilities":
  [
    {
      "browserName": "OnePlusOne",
      "deviceName": "14b2b276",
      "version":"6.0.1",
      "maxInstances": 3,
      "platform":"ANDROID",
      "platformName":"ANDROID"
    }
  ],
  "configuration":
  {
    "cleanUpCycle":2000,
    "timeout":30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url":"http://localhost:4490/wd/hub",
    "host": "localhost",
    "port": 4490,
    "maxSession": 5,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4433,
    "hubHost": "localhost"
  }
}

运行硒网格:

java -jar selenium-server.jar -role hub -port 4433 

运行第一个方案

node.exe node_modules\appium\bin\appium.js --nodeconfig myfirstscenario.json -p 4490 -U 14b2b276 -bp 5490 --chromedriver-port 6490

运行第二种情况

node.exe node_modules\appium\bin\appium.js --nodeconfig mysecondscenario.json -p 4491 -U 04157df40862d02f -bp 5491 --chromedriver-port 6491

考试

@BeforeTest(alwaysRun = true)
public void setUp(){

    try {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "ANDROID");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "");
        capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, appPackage);
        capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, appActivity);

        driver = new AndroidDriver(new URL("http://localhost:4433/wd/hub"), capabilities);
        new webdriverwait(driver, 60);
    } catch (MalformedURLException e) {
        e.printstacktrace();
    }

}

@Test
public void test(){
    System.out.println("hello world");

    try {
        sleep(6000);
    } catch (InterruptedException e) {
        e.printstacktrace();
    }
}


@AfterTest(alwaysRun = true)
public void closeDriver(){
    driver.quit();
}

解决方法:

问题是因为您既未提供DesiredCapabilities中唯一的内容,也未添加自定义CapabilityMatcher.默认情况下,网格仅使用browserName,版本和平台来决定将测试路由到哪个节点.

这是解决问题的一种方法.将一个名为“ applicationName”的新密钥添加到您的nodeConfig.json中,并分别设置“ OnePlusOne”和“ SamsungS6”的值.然后,将一个名为“ applicationName”的新功能添加到测试中所需的功能,然后分别设置“ OnePlusOne”和“ SamsungS6”的值.之后,您的测试将被路由到正确的设备.

您可以在我的博客文章here中了解有关此内容的更多信息.

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

我之前使用IWebDriver控制IE进行测试.但是IWebDriver和IWebElement支持的方法非常有限.我发现属于Selenium命名空间的ISelenium / DefaultSelenium非常有用.如何在不安装Selenium Server的情况下使用它们来控制IE?

这是DefaultSelenium的构造函数:

ISelenium sele = new DefaultSelenium(**serveraddr**,**serverport**,browser,url2test);
sele.Start();
sele.open();
...

似乎我必须在创建ISelenium对象之前安装Selenium Server.

我的情况是,我正在尝试使用C#Selenium构建一个.exe应用程序,它可以在不同的PC上运行,并且不可能在所有PC上安装Selenium Server(你永远不知道哪个是下一个运行应用程序).

有没有人知道如何在不安装服务器的情况下使用ISelenium / DefaultSelenium?
谢谢!

解决方法

在不使用RC Server的情况下,Java中有一些解决方案:

1)对于selenium浏览器启动:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setbrowserName("safari");
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"),new URL("http://www.google.com/"),capabilities);
WebDriver driver = new RemoteWebDriver(executor,capabilities);

2)对于selenium命令:

// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();

// A "base url",used by selenium to resolve relative URLs
 String baseUrl = "http://www.google.com";

// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver,baseUrl);

// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q","cheese");
selenium.click("name=btnG");

// Get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver();

//Finally,close the browser. Call stop on the WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise,the JVM will continue running after
//the browser has been closed.
selenium.stop();

描述于此:http://seleniumhq.org/docs/03_webdriver.html

谷歌在C#中有类似的东西.没有其他方法可以实现这一目标.

Docker,Django和Selenium-Selenium无法连接

Docker,Django和Selenium-Selenium无法连接

我已经将Docker配置为使用docker-compose.yml运行Postgres和Django,并且工作正常。

我遇到的麻烦是Selenium无法连接到Django liveserver。

现在(至少对我而言),django必须访问selenium才能控制浏览器,而selenium必须访问django才能访问服务器。

我已经尝试从此处使用docker-
compose.yml的以下配置使用docker’大使’模式:https
:
//github.com/docker/compose/issues/666

postgis:  dockerfile: ./docker/postgis/Dockerfile  build: .  container_name: postgisdjango-ambassador:  container_name: django-ambassador  image: cpuguy83/docker-grand-ambassador  volumes:    - "/var/run/docker.sock:/var/run/docker.sock"  command: "-name django -name selenium"django:  dockerfile: ./docker/Dockerfile-dev  build: .  command: python /app/project/manage.py test my-app  container_name: django  volumes:    - .:/app  ports:    - "8000:8000"    - "8081:8081"  links:    - postgis    - "django-ambassador:selenium"  environment:    - SELENIUM_HOST=http://selenium:4444/wd/hubselenium:  container_name: selenium  image: selenium/standalone-firefox-debug  ports:    - "4444:4444"    - "5900:5900"  links:    - "django-ambassador:django"

当我检查http:// DOCKER-MACHINE-IP:4444 / wd / hub / static / resource /
hub.html时,
我可以看到Firefox启动了,但是由于Firefox无法连接到Django,所有测试都失败了

''Firefox can''t establish a connection to the server at localhost:8081''

我也在这里https://github.com/docker/compose/issues/1991尝试了此解决方案,
但是这不起作用,因为我无法让django同时连接到Postgis和Selenium

''django.db.utils.OperationalError: could not translate host name "postgis" to address: Name or service not known''

我尝试使用下面列出的网络功能

postgis:  dockerfile: ./docker/postgis/Dockerfile  build: .  container_name: postgis  net: appnetdjango:  dockerfile: ./docker/Dockerfile-dev  build: .  command: python /app/project/manage.py test foo  container_name: django  volumes:    - .:/app  ports:    - "8000:8000"    - "8081:8081"  net: appnet  environment:    - SELENIUM_HOST=http://selenium:4444/wd/hubselenium:  container_name: selenium  image: selenium/standalone-firefox-debug  ports:    - "4444:4444"    - "5900:5900"  net: appnet

但结果是一样的

''Firefox can''t establish a connection to the server at localhost:8081''

那么我怎样才能使selenium连接到Django?

我已经玩了好几天了-非常感谢您的帮助。

更多信息

另一个怪异的事情是,如果我运行./manage.py test foo,那么当测试服务器运行时 使用docker
(使用我的virtualenv等旧配置)时,我可以通过http://
localhost:8081上的任何浏览器访问服务器,并且获取提供的网页,但是如果我在docker下运行等效命令,则无法访问测试服务器。这很奇怪,因为我正在映射端口8081:8081-这与之相关吗?

注意:我正在使用OSX和Docker v1.9.1

答案1

小编典典

我最终提出了一个更好的解决方案,该解决方案不需要我对IP地址进行硬编码。以下是我使用docker在django中运行测试的配置。

Docker组成文件

# docker-compose base file for everythingversion: ''2''services:  postgis:    build:      context: .      dockerfile: ./docker/postgis/Dockerfile    container_name: postgis    volumes:      # If you are using boot2docker, postgres data has to live in the VM for now until #581 fixed      # for more info see here: https://github.com/boot2docker/boot2docker/issues/581      - /data/dev/docker_cookiecutter/postgres:/var/lib/postgresql/data  django:    build:      context: .      dockerfile: ./docker/django/Dockerfile    container_name: django    volumes:      - .:/app    depends_on:      - selenium      - postgis    environment:      - SITE_DOMAIN=django      - DJANGO_SETTINGS_MODULE=settings.my_dev_settings    links:      - postgis      - mailcatcher  selenium:    container_name: selenium    image: selenium/standalone-firefox-debug:2.52.0    ports:      - "4444:4444"      - "5900:5900"

Dockerfile(对于Django)

ENTRYPOINT ["/docker/django/entrypoint.sh"]

在入口点文件中

#!/bin/bashset -e# Now we need to get the ip address of this container so we can supply it as an environmental# variable for django so that selenium knows what url the test server is on# Use below or alternatively you could have used# something like "$@ --liveserver=$THIS_DOCKER_CONTAINER_TEST_SERVER"if [[ "''$*''" == *"manage.py test"* ]]  # only add if ''manage.py test'' in the argsthen  # get the container id  THIS_CONTAINER_ID_LONG=`cat /proc/self/cgroup | grep ''docker'' | sed ''s/^.*\///'' | tail -n1`  # take the first 12 characters - that is the format used in /etc/hosts  THIS_CONTAINER_ID_SHORT=${THIS_CONTAINER_ID_LONG:0:12}  # search /etc/hosts for the line with the ip address which will look like this:  #     172.18.0.4    8886629d38e6  THIS_DOCKER_CONTAINER_IP_LINE=`cat /etc/hosts | grep $THIS_CONTAINER_ID_SHORT`  # take the ip address from this  THIS_DOCKER_CONTAINER_IP=`(echo $THIS_DOCKER_CONTAINER_IP_LINE | grep -o ''[0-9]\+[.][0-9]\+[.][0-9]\+[.][0-9]\+'')`  # add the port you want on the end  # Issues here include: django changing port if in use (I think)  # and parallel tests needing multiple ports etc.  THIS_DOCKER_CONTAINER_TEST_SERVER="$THIS_DOCKER_CONTAINER_IP:8081"  echo "this docker container test server = $THIS_DOCKER_CONTAINER_TEST_SERVER"  export DJANGO_LIVE_TEST_SERVER_ADDRESS=$THIS_DOCKER_CONTAINER_TEST_SERVERfieval "$@"

在您的Django设置文件中

SITE_DOMAIN = ''django''

然后运行测试

docker-compose run django ./manage.py test

Excel vba selenium - 单击坐标

Excel vba selenium - 单击坐标

如何解决Excel vba selenium - 单击坐标?

我正在尝试编写一个工具,可以点击网页上的特定坐标。

没有我要识别的元素,都是图像(我假设是闪光灯或其他东西)

我找到了这个页面

Clicking at coordinates without identifying element

这建议使用 ActionChains,并且看起来正是我想要做的。 但是该页面似乎是用 python 编写的(下面是该页面的代码,我正在尝试复制)

from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_by_offset(X coordinates,Y coordinates).click().perform()

我不知道如何在 VBA 中做等效的事情

解决方法

在 VBA 中,我们这样做:

driver.Actions.MoveByOffset(offset_x,offset_y).Perform

Read the official Selenium VBA wrapper - GitHub

这是内部实现:

Public Function MoveByOffset ( 
    offsetX As Integer,offsetY As Integer
) As Actions

今天关于使用VBA和Selenium来驱动网站vba任务驱动教程的介绍到此结束,谢谢您的阅读,有关Android-使用Appium和Selenium网格进行并行测试、c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、Docker,Django和Selenium-Selenium无法连接、Excel vba selenium - 单击坐标等更多相关知识的信息可以在本站进行查询。

本文标签: