English 中文(简体)
利用 se网络驱动器从前文件查询链接
原标题:Visit links from excel file using selenium web driver

我有一份Excel文件,我的所有链接都存放在一栏。 每一行都有一个链接。 For E.g:

www.example.com
www.test.com
www.demo.com

等等。 我想做的是访问每一个环节,并在诺埃尔开放。 联系地址,并与外壳细胞链接进行比较。 如果两者都相同,则在下个牢房中设置了“Pas”号,否则将铺设“Fail”。 我如何这样做。 您能否给我一个样本。 我正在使用 j网司机。

这是我尝试的:

try {
    FileInputStream file=new FileInputStream(new File(path));
    FileOutputStream outFile=new FileOutputStream(new File(path));
    HSSFWorkbook workbook=new HSSFWorkbook(file);
    HSSFSheet sheet=workbook.getSheetAt(0);
    HSSFCell cell=null;     
    int s=sheet.getLastRowNum()+1;
    for(int i=0; i<s; i++){
        cell=sheet.getRow(i).getCell(0);
        String url=cell.toString();
        driver.get(url);
        Thread.sleep(10000);
        String urlnew=driver.getCurrentUrl().toString();
        HSSFRow row=sheet.getRow(i);
        HSSFCell cellresult=row.createCell(1);
        if(url==urlnew){
            cellresult.setCellValue("Pass");
        }else{
            cellresult.setCellValue("fail");
        }
        workbook.write(outFile);
    }    
    file.close();  
    outFile.close();
} 
问题回答
  1. driver = webdriver.Firefox();
  2. Load the Excel file (you can use this)
  3. In the rows loop, add this code: driver.get(< cell URL>);

在你的法典中,你使用了以下声明来比较两条插图。

if(url==urlnew)

使用以下代码。 它将开展工作。

if(url.equals(urlnew))

欲了解更多有关“强力比较”的信息,请恰this链接。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签