Mon scénario consiste à rechercher n'importe quel ordinateur portable de marque et je dois sélectionner le prix le plus élevé dans la page en cours sans trier.Automatisation de l'application Flipkart à l'aide de Selenium WebDriver
@BeforeClass
public void launchBrowser()
{
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.flipkart.com");
}
@Test(priority = 0)
public void searchComputers() throws InterruptedException
{
WebDriverWait wait = new WebDriverWait(driver, 40);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@title='Search for Products, Brands and More']")));
driver.findElement(By.xpath("//div[@class='O8ZS_U']/input")).sendKeys("laptops");
driver.findElement(By.xpath("//div[@class='O8ZS_U']/input")).sendKeys(Keys.ENTER);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@title='HP']//div[@class='_1p7h2j']")));
Thread.sleep(1000);
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");
driver.findElement(By.xpath("//div[@title='HP']//div[@class='_1p7h2j']")).click();
}
@Test(priority = 1)
public void searchHPComputers() throws InterruptedException
{
Thread.sleep(2000);
WebDriverWait wait1 = new WebDriverWait(driver, 40);
wait1.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//li[text()='Newest First']")));
Thread.sleep(1000);
List<WebElement> element = driver.findElements(By.xpath("//div[@class='_1vC4OE _2rQ-NK']"));
for(WebElement web : element)
{
String amount = web.getText();
int length = amount.length();
String price = amount.substring(1, length);
System.out.println("Amount : "+ price);
Thread.sleep(1000);
}
}
@AfterClass
public void closeBrowser() throws InterruptedException
{
Thread.sleep(2000);
driver.close();
driver.quit();
}
J'ai imprimé toute la liste de prix dans la page actuelle dans la console eclipse. Mais je n'ai aucune idée de comment cliquer sur le portable le plus cher. Veuillez m'aider à résoudre ce problème.
je dois choisir l'ordinateur portable de prix le plus élevé dans la page en cours sans tri. –
@MohanKumar: essayez la partie mise à jour – kushal
Cela a fonctionné ... !!!!!!!! Je vous remercie. –