我想要从 flipkart 和亚马逊网站比较的商品的最低价格。我正在这两个网站上搜索特定的手机
public static void main(String arg[]) throws InterruptedException {
ArrayList<String[]> data1 = new ArrayList<String[]>();
String[] entriesArr = null;
String[] entriesArr1 = null; System.setProperty("webdriver.chrome.driver","C:\\Seleniumjava\\driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
//open flipkart
driver.get("https:/www.flipkart.com");
//xpath for close the popup
driver.findElement(By.xpath("//button[text()='✕']")).click();
driver.findElement(By.xpath("//div[@class='O8ZS_U']/input")).sendKeys("Redmi 7 ( 32 MB , 2 GB ) Black");
driver.findElement(By.xpath("//div[@class='O8ZS_U']/input")).sendKeys(Keys.ENTER);
List<WebElement> phonenames = driver.findElements(By.xpath("//div[@class='_3wU53n']"));
List<WebElement> phoneprice = driver.findElements(By.xpath("//div[@class='_1vC4OE _2rQ-NK']"));
for( int i=0;i<phonenames.size();i++)
{
if(phonenames.get(i).getText().contains("Redmi 7 (Eclipse Black, 32 GB)"))
{
entriesArr = new String[]{phonenames.get(i).getText().toString(), phoneprice.get(i).getText().toString() };
data1.add(entriesArr);
}
}
当我运行我的代码时,它显示 String index out of range: -1 in the line int value = Integer.parseInt(data.get(i)[1].substring(1).replace(",", "")) ;
桃花长相依
相关分类