要件:Indeed.comへ QAエンジニアを使用するフィールドでは、シアトル、ワシントン州のどこのフィールドを使用しますか。 Amazonまたはオートメーションを除くすべてのページからジョブの説明/タイトルを印刷非表示のページからの情報の取得
問題:Firepathでこのxpathを使用しています// div [contains(@ id、 'p')] [contains(@ class、 'row' )]は、第1ページのすべての ジョブを選択します。しかし、私が下のコードを実行すると、最初のページ の最初の仕事の説明が何度も何度も印刷されますが、同時に他のページをクリックし続けます。私は取得しています
出力:
SENIOR品質保証ENGINEER- CIVIL ... サウンドトランジット - 12件のレビュー - シアトル、WA 79626 $ - $ 99533年 メンター、コーチ、確立維持にQAエンジニアをガイド仕事の基準。 QAへのガイダンスを提供することで、QAグループ内で一貫性をサポートしています... ジョブ が
をスポンサー保存コード:import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class QAJob {
int MAX_PAGES;
@Test
public void jobSearch(){
WebDriver driver= new FirefoxDriver();
driver.get("https://www.indeed.com");
driver.findElement(By.id("what")).sendKeys("QA Engineer");
driver.findElement(By.id("where")).clear();
driver.findElement(By.id("where")).sendKeys("Seattle,WA");
driver.findElement(By.id("fj")).click();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// Close the pop up window that appears
driver.findElement(By.id("prime-popover-close-button")).click();
//Code to scroll down
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.scrollBy(0,1000)", "");
//Find and print the number of pages found for search
List<WebElement> search_pages=driver.findElements(By.xpath("//div[contains(@class,'pagination')]//a"));
System.out.println("Number of pages found for job search is " +search_pages.size());
//Code to get and print job descriptions,title
List<WebElement> job_desc=driver.findElements(By.xpath("//div[contains(@id,'p')][contains(@class,'row')]"));
for(WebElement e: job_desc){
//using String so that I can use 'contains'
String str_job_description=e.getText();
while(search_pages.size()!=0){
//find Next link and click on it till the size is !=0 to get to last page
driver.findElement(By.xpath("//span[contains(@class,'np')][contains(text(),'Next')]")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Do not want Amazon or Automation jobs
if(!((str_job_description.contains("Automation")) || (str_job_description.contains("Amazon")))){
System.out.println(str_job_description);
}
}
}
}
}
私はいくつかの有用な提案/アイデアを使用することができます。あなたの時間を事前に感謝します。