【问题标题】:Can I open website URL from Excel data file using Selenium IDE?我可以使用 Selenium IDE 从 Excel 数据文件中打开网站 URL 吗?
【发布时间】:2016-03-03 08:45:35
【问题描述】:

我有一个 Excel 文件,其中包含我需要打开的所有 URL

例如:

1. example.com/archiveData.php?edit=testcase&id=29
2. example.com/archiveData.php?edit=testcase&id=30
3. example.com/archiveData.php?edit=testcase&id=31
4. example.com/archiveData.php?edit=testcase&id=32
5. example.com/archiveData.php?edit=testcase&id=33
6. example.com/archiveData.php?edit=testcase&id=34
...

(大约 3000 个 URL T_T)

我无法手动打开它,所以我想使用 Selenium IDE 来执行此操作 由于我是 Selenium 的新手,所以任何人都可以帮助我回答我的问题...我可以使用 Selenium IDE 从 Excel 数据文件中打开网站 URL 吗?

或者请提出任何我可以轻松完成的免费工具

非常感谢!

【问题讨论】:

  • 打开页面后还需要做什么?如果您需要屏幕截图 AutoIt 就可以了,如果您需要与之交互,那么您应该学习 selenium。
  • 是的,这可以从 Csv(不是 excel)打开 url。打开后你想做什么?网址将在同一选项卡中打开。
  • 谢谢大家,我想打开url然后在那个链接中插入一些数据,我还有一组数据需要输入

标签: selenium


【解决方案1】:

没有。您不能使用Selenium IDE 来解决您的问题,因为它旨在模拟网络浏览器中的用户操作。但是您可以使用编程语言,例如Python 来读取Excel 文件内容(xlrd 模块)并在同一脚本中导航到所需的URLsSelenium WebDriver 模块)。

此外,如果您使用Windows 操作系统,您可以尝试使用AutoIT/AutoHotKey 自动化工具来实现相同目的。

【讨论】:

  • 谢谢,我将使用 Selenium WebDriver
【解决方案2】:

您可以通过 selenium RC 或 webdriver 完成,只需几行代码。尝试了解硒的基础知识。

【讨论】:

    【解决方案3】:

    如果您可以将 Excel 文件转换为以行分隔的文本文件,那么这很容易通过将文件读取到数组中来实现,然后在 while 循环中根据数组值操作数据。

    例子:

    Links.txt

    www.google.com
    www.facebook.com
    www.youtube.com
    www.tumblr.com
    www.amarokstudios.com
    

    OpenLinks.au3

    #include <file.au3>
    
    ; Create an empty array to store the links later on in the script.
    DIM $aArray
    
    ; Read you Links.txt file to an array, if there is an error, display an error message.
    
    If _FileReadToArray(@ScriptDir & "\Links.txt", $aArray) then
    Else
      MsgBox(0,"Error","An error occurred trying to read your file to an array!")
    EndIf
    
    ; Now, all of the links should be stored in the array called "$aArray". The size of the array is stored in $aArray[0], the first link is in $aArray[1], second in $aArray[2], and so on.
    
    ; Now, we are going to declare the starting size of the array, so the loop knows how many times to run the code.
    
    $i = $aArray[0]
    ; Next, we will declare the link to start on. Since the first link is stored in $aArray[1], we will set the value to 1.
    $link = 1
    
    ; Now we will create a while loop that will run while the array size is larger than zero.
    
    While $i > 0
    ; Open the Windows RUN box
    Send("#r")
    Sleep(250)
    ; Send the value of $aArray[$link]. Since we previously set $link equal to 1, it will send the value of $aArray[1], which as we said earlier, would contain the first link on our list.
    Send($aArray[$link])
    ; Send the enter key
    Send("{ENTER}")
    ; Sleep for 1 second to prevent code from overlapping itself
    Sleep(1000)
    
    #CS
        You can put code here to manipulate the data on each website. There are many different ways to do this. For example, if the location for each piece of data is the same, you could simple write one script here that will execute each time a new page loads.
    
        Another method is to create an if statement to check which website is currently loaded, then writing the logic For each page. Tedious, but well worth it if you are going to be doing this for the same pages.
    
    #CE
    
    ; Add the value of 1 to the current link variable so the script can move on to the next link. For example, the first value of $aArray[$link] was equal to $aArray[1], but adding 1 to it would change $aArray[$link] to $aArray[2]
    
    $link += 1
    
    ; Subtract 1 from the total array size so the loop knows how many more times to execute.
    $i -= 1
    
    ; End the loop
    WEnd
    

    这里是没有 cmets 的代码,所以你可以看看它是如何工作的。

    #include <file.au3>
    
    Dim $aArray
    If _FileReadToArray(@ScriptDir & "\Links.txt",$aArray) then 
    Else
       MsgBox(0,"Error","Error from Function")
    EndIf
    
    $i = $aArray[0]
    $link = 1
    while $i > 0
        Send("#r")
        Sleep(250)
        Send($aArray[$link])
        Send("{Enter}")
        Sleep(1000)
    
        ; Your code to manipulate data here
        $link += 1
        $i -= 1
    WEnd
    

    我知道这并不能具体回答您的问题,但我希望它为您提供了一个合理的选择。使用这种方法,您无需下载任何 UDF,而且代码非常短。

    如果您有任何问题,请随时告诉我。我不介意帮助你解决这个问题,直到它适合你!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 2016-08-02
      相关资源
      最近更新 更多