Java 从不可见页面获取信息
要求:访问www.com 在哪个领域使用QA工程师,在哪里使用华盛顿州西雅图。 打印除Amazon或Automation之外的所有页面上的职务说明/标题 问题:在Firepath中,我使用的xpath//div[contains(@id,'p')][contains(@class,'row')]选择所有 作业在第一页。然而,当我执行下面的代码时,它只打印第一页的第一份工作描述 一遍又一遍,同时不断地同时点击其他页面 我得到的输出: 高级质量保证工程师-土木工程。。。 声音传输-12评论-华盛顿州西雅图 每年79626-99533美元 指导QA工程师维护既定的工作标准。通过向QA提供指导,支持QA团队内部的一致性。。。 保存作业 赞助 代码:Java 从不可见页面获取信息,java,selenium-webdriver,Java,Selenium Webdriver,要求:访问www.com 在哪个领域使用QA工程师,在哪里使用华盛顿州西雅图。 打印除Amazon或Automation之外的所有页面上的职务说明/标题 问题:在Firepath中,我使用的xpath//div[contains(@id,'p')][contains(@class,'row')]选择所有 作业在第一页。然而,当我执行下面的代码时,它只打印第一页的第一份工作描述 一遍又一遍,同时不断地同时点击其他页面 我得到的输出: 高级质量保证工程师-土木工程。。。 声音传输-12评论-华盛顿州
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);
}
}
}
}
}
import java.util.List;
导入java.util.concurrent.TimeUnit;
导入org.junit.Test;
导入org.openqa.selenium.By;
导入org.openqa.selenium.JavascriptExecutor;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.interactions.Actions;
公共类QAJob{
int MAX_页;
@试验
公开招聘{
WebDriver=newfirefoxdriver();
驱动程序。获取(“https://www.indeed.com");
driver.findElement(By.id(“what”)).sendKeys(“QA工程师”);
driver.findElement(By.id(“where”)).clear();
driver.findElement(By.id(“where”)).sendKeys(“华盛顿州西雅图”);
driver.findElement(By.id(“fj”))。单击();
driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
//关闭出现的弹出窗口
driver.findElement(By.id(“主弹出关闭按钮”))。单击();
//要向下滚动的代码
JavascriptExecutor jse=(JavascriptExecutor)驱动程序;
jse.executeScript(“window.scrollBy(01000)”,“”);
//查找并打印为搜索找到的页数
List search_pages=driver.findElements(By.xpath(“//div[contains(@class,'pagination')]//a”);
System.out.println(“为求职找到的页数为”+search_pages.size());
//获取和打印工作描述、职位的代码
List job_desc=driver.findElements(By.xpath(//div[contains(@id,'p')]][contains(@class,'row')]);
for(WebElement e:job_desc){
//使用字符串以便我可以使用“contains”
字符串str_job_description=e.getText();
while(search_pages.size()!=0){
//找到下一个链接并单击它,直到大小为!=0才能进入最后一页
findElement(By.xpath(//span[contains(@class,'np')][contains(text(),'Next')])))。单击();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
//不想要亚马逊或自动化作业
if(!((str_job_description.contains(“自动化”))(str_job_description.contains(“亚马逊”)){
System.out.println(str_作业描述);
}
}
}
}
}
我需要一些有用的建议/想法。提前感谢您的时间。对于您在
job\u desc
中的每个元素(外部用于循环),您将单击下一步按钮,直到到达最后一页(内部而循环)。的循环应该在中,而则在中。您可以尝试类似的方法(未经测试)
对于job_desc
(外部用于循环)中的每个元素,单击下一步按钮,直到到达最后一页(内部而循环)。的循环应该在中,而则在中。您可以尝试类似的方法(未经测试)
while(search_pages.size() != 0) {
List<WebElement> job_desc=driver.findElements(By.xpath("//div[contains(@id,'p')][contains(@class,'row')]"));
for(WebElement e: job_desc){
String str_job_description=e.getText();
if(!((str_job_description.contains("Automation")) || (str_job_description.contains("Amazon"))) ){
System.out.println(str_job_description);
}
}
driver.findElement(By.xpath("//span[contains(@class,'np')][contains(text(),'Next')]")).click();
}
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By by));