以下のコードを使用してリンクページを開き、モバイルセクションに行き、名前順に基づいてアイテムをソートしようとしています。今、私は、モバイルデバイスがアルファベット順の名前でソートされているかどうかをチェックしたい。 私はそれらをループ、親切にこれを行うにはウェブ要素が整っているかどうかをチェックする方法は?
package selflearning;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Guru99Ecommerce1 {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.gecko.driver","C:\\geckodriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://live.guru99.com/index.php/");
String title=driver.getTitle();
String expectedTitle = "Home page";
System.out.println("The title of the webPage is " + title);
expectedTitle.equalsIgnoreCase(title);
System.out.println("Title is verified");
driver.findElement(By.xpath("//a[text()='Mobile']")).click();
String nextTitle = driver.getTitle();
System.out.println("The title of next page" + nextTitle);
String nextExpectedTitle = "pageMobile";
nextExpectedTitle.equalsIgnoreCase(nextTitle);
System.out.println("The next title is verified");
Select s = new Select(driver.findElement(By.xpath("//div[@class='category-products']//div/div[@class='sorter']/div/select[@title='Sort By']")));
s.selectByVisibleText("Name");
List<WebElement> element = driver.findElements(By.xpath("//div[@class='product-info']/h2/a"));
for(WebElement e: element)
{
String str = e.getText();
System.out.println("The items are " + str);
}
HashSet<WebElement> value = new
List<WebElement> list = new ArrayList<WebElement>(element);
list.addAll(element);
System.out.println("arrangement" + list);
}
}
はあなたが達成したいものを展示し、いくつかの例を追加してくださいすることができ
?リストは現在どのように見えますか?リストがソートされているかどうかを調べるには、その要素をトラバースして、要素が前の要素よりも大きいか等しいかをチェックします。または、ソートして、結果のリストが入力リストと等しいかどうかを確認することができます(注文を変更する可能性のある要素がない場合にのみ機能します)。 – Zabuza
最後の行にコードがありません: 'HashSet value = new'。 –
Zabuza
私はハッシュセットをしようとしていましたが、達成することができませんでした –