シナリオ:HotmailのYahoo.com検索に行き、すべての検索ページを1つずつクリックしてください。すべての結果リンクをクリックしてください
マイコード:結果ページのリンクを印刷するだけです。ページが残っていない間に2,3,4ページをクリックする方法はありますか?
あなたが何か必要なので、あなたのケースでは、next
リンクは、クラス
next
を持って、要素を見つけるために、クラス名を使用することができセレンで
public class QAJob {
@Test
public void jobSearch(){
WebDriver driver= new FirefoxDriver();
driver.get("https://yahoo.com");
driver.findElement(By.id("uh-search-box")).sendKeys("hotmail");
driver.findElement(By.id("uh-search-button")).click();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//scroll down
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.scrollBy(0,1000)", "");
List<WebElement> result_pages=driver.findElements(By.xpath("//div[contains(@class,'pagination')]//a[contains(@title,'')]"));
for (WebElement e: result_pages){
Actions action= new Actions(driver);
WebElement search_results=driver.findElement(By.xpath("//div[contains(@class,'pagination')]//a[contains(@title,'')]"));
System.out.println(e.getAttribute("outerHTML"));
}
}
}
「すべての検索ページを1つずつ」とはどういう意味ですか?複数のクリックは同時にですか? – Andersson
私はあなたの問題をよく理解していない、あなたはリンクをクリックできないと私は理解した? e-click() –
ページ2,3,4のxpathを見つけてハードコードしますが、ページ2、ページ3をクリックできるようにしたいのですが、次のページでは、xpathをハードコードする必要はありません。複数のクリックを同時に行います。 –