Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Java 使用selenium从字段检索数据_Java_Selenium_Automation - Fatal编程技术网

Java 使用selenium从字段检索数据

Java 使用selenium从字段检索数据,java,selenium,automation,Java,Selenium,Automation,我是自动化测试Selenium、JavaLang和Eclipse的初学者 我试图从网页中获取一些值并将它们存储在excel中 输入值取自excel,输出将存储在excel中 我现在面临的问题是,让我举个例子告诉你 首先,它从excel中获取帐号(比如123)并输入到搜索字段,然后选择合适的帐户并获取名称和电子邮件 其次,下一个帐号234是从excel中提取的,并输入到搜索字段中,然后它获得该帐号234的适当名称和电子邮件 我现在只尝试使用两个帐户 因此,当我看到输出,或者更确切地说打开excel

我是自动化测试Selenium、JavaLang和Eclipse的初学者

我试图从网页中获取一些值并将它们存储在excel中

输入值取自excel,输出将存储在excel中

我现在面临的问题是,让我举个例子告诉你

首先,它从excel中获取帐号(比如123)并输入到搜索字段,然后选择合适的帐户并获取名称和电子邮件

其次,下一个帐号234是从excel中提取的,并输入到搜索字段中,然后它获得该帐号234的适当名称和电子邮件

我现在只尝试使用两个帐户

因此,当我看到输出,或者更确切地说打开excel文件时,我只会在两列中得到最后一个帐户所有者的名称和编号

我需要的结果是在一列中显示第一个帐户名和电子邮件,在另一列中显示第二个帐户名和电子邮件

我请求所有的人帮我解决这个问题

谢谢你的关注

int rc= ws.getRows();
代码如下:

WebElement s1=driver.findElement(By.xpath("//table[@id='kInfo']/tbody/tr[10]/td"));
       //WebElement s1=driver.findElement(By.xpath("//td[@class='tRight']/a"));
          String s2=s1.getText();
          System.out.println("data:"+s2);

          String D1= driver.findElement(By.xpath("//div[@class='vcard clearfix']")).getText();
          System.out.println(D1);
       Thread.sleep(1000);
       /*driver.findElement(By.xpath("//*[@id='homePage']")).click();
       driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
       Thread.sleep(1000);*/

       WritableWorkbook wb1 = Workbook.createWorkbook( new File("C:\\Bhasker-DNT\\Excel\\ouput.xls"));
       WritableSheet ws1 = wb1.createSheet("customsheet", 1);
       {
        for(int count=0;count<4;count++)
        {
            for(int i=0;i<rc-1;i++)
            {
            Label label = new Label(i, 0, s2);
               ws1.addCell(label);

               Label label1 = new Label(i, 1, D1);
               ws1.addCell(label1);
            }           
        }
       //Label label = new Label(0, 0, s2); 
       //ws1.addCell(label);
       }
       wb1.write();
       wb1.close();

要获取div、selection或p的元素,您需要xpath,我想您已经有了它。


我希望它有帮助,如果没有,请提供一些来自html和excel的示例。

感谢您的回复。在这种情况下,我没有要打印的列表。一个场景重复多次,收集多个帐号的姓名和电子邮件。应打印每个帐户的名称和电子邮件,但此处仅打印最后一个帐户名称n电子邮件,而不是全部。非常感谢。您可以将xml或html代码复制到某个地方吗?要将这些数据复制到的位置。虚拟数据仅用于查看确切的结构
String name = ""
    List<WebElement> your_list= driver.findElements(By.xpath("xpath_stuff or workbook.get(I)"));


                for (int i=0; i<your_list.size(); i++) {
                //  System.out.println(i+ ". " + your_list.get(i).getText());
                    // here you can write the elements to excel.
  //if you need first name you need to just
                   if(i==(you know which is the first row that conatins the name)
                        {
                          name = your_list.get(i).getText();
                         }


   ... the same way the email and the other
                ws1.addCell(your_list.get(i).getText());
                }

       wb1.close();