【发布时间】:2019-11-19 04:31:10
【问题描述】:
我尝试执行相同的逻辑来从pepperfry.com 获取学习灯的报价,但我得到了ArrayIndexBoudn 异常。请找到以下代码:
代码
package com.Ecommerce;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class PageLaunch {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C://Users//484834//Downloads//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.pepperfry.com");
driver.manage().window().maximize();
Thread.sleep(8000);
driver.switchTo().frame("notification-frame-22a3358b6");
driver.findElement(By.cssSelector("span.wewidgeticon.we_close.icon-large")).click(); // Close first pop Up
System.out.println("************Closed First Pop UP************");
driver.switchTo().defaultContent();
Thread.sleep(8000);
//driver.switchTo().alert().dismiss();
//driver.findElement(By.xpath("//*[@id='signinupPopupBox']/a")).click();
//System.out.println("************Closed Second Pop UP************");
driver.findElement(By.xpath("//input[@itemprop='query-input']")).sendKeys("study lamp");
driver.findElement(By.xpath("//input[@itemprop='query-input']")).sendKeys(Keys.ENTER);
System.out.println("************Study Lamps are Searched************");
Thread.sleep(8000);
driver.switchTo().frame("webklipper-publisher-widget-container-notification-frame");
driver.findElement(By.cssSelector("span.wewidgeticon.we_close.icon-large")).click();
System.out.println("************Closed Third Pop UP************");
driver.switchTo().defaultContent();
List<WebElement> productPrices = driver.findElements(By.cssSelector("span.clip-offr-price "));
System.out.println("Size is "+productPrices.size());
for(int i=0;i<productPrices.size();i++)
{
//System.out.println(productPrices);
String[] price = productPrices.get(i).getText().split(".");
//Rs.1,239
String p = price[1].replace(",", "");
int actualPrice =Integer.parseInt(p);
System.out.println("Actual Price of Study lamp is "+actualPrice);
}
}
}
输出
启动 ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}) 在 5562 端口上
只允许本地连接。
请保护 ChromeDriver 和相关测试框架使用的端口 防止恶意代码访问。
2019 年 11 月 18 日下午 5:04:27 org.openqa.selenium.remote.ProtocolHandshake 创建会话
信息:检测到的方言:W3C
************Closed First Pop UP************
************研究灯被搜索************
************关闭第三个弹出窗口************
尺寸为 48
线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 1
在 com.Ecommerce.PageLaunch.main(PageLaunch.java:54)
【问题讨论】:
标签: selenium