gpt4 book ai didi

java - Selenium WebDriver 上传文件/关闭资源管理器窗口

转载 作者:行者123 更新时间:2023-12-02 06:40:02 27 4
gpt4 key购买 nike

我在上传文件和关闭 Windows 资源管理器窗口时遇到一些问题。测试运行良好,我没有收到任何错误,但文件永远不会上传,上传弹出窗口永远不会关闭。

ApplyJob.java

package com.example.tests;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

public class IJ_ApplyForJob {

IJ_Login login = new IJ_Login();

@Test
public void SFJ_HomeSearchBoxNotLoggedIn(WebDriver driver)
{
driver.findElement(By.id("kwdInput")).clear();
driver.findElement(By.id("kwdInput")).sendKeys("Testing");
//find the dropdown and search for the location dublin
Select ddSelectLoc = new Select(driver.findElement(By.name("Location")));
ddSelectLoc.selectByVisibleText("Dublin");
//find the dropdown and search for the Category IT
Select ddSelectCat = new Select(driver.findElement(By.id("home-category")));
ddSelectCat.selectByVisibleText("IT");
//click search button and search for term.
driver.findElement(By.className("btn-search")).click();
//click first job title
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucJobs_rptResult_ctl01_hlTitle")).click();
//click apply for job
driver.findElement(By.className("ApplyForJobButton")).click();
//complete form
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtComments")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtComments")).sendKeys("Cover Letter Testing");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtFirstName")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtFirstName")).sendKeys("Name");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtSecondName")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtSecondName")).sendKeys("Surname");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtPhone")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtPhone")).sendKeys("12345678");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtEmail")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtEmail")).sendKeys("email@gmail.com");
// Upload CV not logged in
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_fileCV")).sendKeys("C:\\Users\\Desktop\\CV_TEST.docx");
driver.findElement(By.linkText("Open")).click();
//submit application
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_btnSubmit")).click();
}
}

IJ_Test.java

package com.example.tests;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class IJ_test {
IJ_ApplyForJob afj = new IJ_ApplyForJob();
IJ_CommonSetup setup = new IJ_CommonSetup();
private WebDriver driver = new FirefoxDriver();

@Test
public void runTest() throws Exception {
setup.setUp(driver);
setup.clearCookies(driver);
afj.SFJ_HomeSearchBoxNotLoggedIn(driver);
//afj.SFJ_HomeSearchBoxLoggedIn(driver);
setup.tearDown();
}

}

我不太确定我哪里出了问题,因此我们将不胜感激。

最佳答案

问题是我从来没有等待简历上传。 @smit的建议对我来说非常有效。通过使用 .implicitlyWait,我能够暂停测试并等待简历上传。

申请工作.java

package com.example.tests;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

public class IJ_ApplyForJob {

IJ_Login login = new IJ_Login();

@Test
public void SFJ_HomeSearchBoxNotLoggedIn(WebDriver driver)
{
driver.findElement(By.id("kwdInput")).clear();
driver.findElement(By.id("kwdInput")).sendKeys("Testing");
//find the dropdown and search for the location dublin
Select ddSelectLoc = new Select(driver.findElement(By.name("Location")));
ddSelectLoc.selectByVisibleText("Dublin");
//find the dropdown and search for the Category IT
Select ddSelectCat = new Select(driver.findElement(By.id("home-category")));
ddSelectCat.selectByVisibleText("IT");
//click search button and search for term.
driver.findElement(By.className("btn-search")).click();
//click first job title
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucJobs_rptResult_ctl02_hlTitle")).click();
//click apply for job
driver.findElement(By.className("ApplyForJobButton")).click();
//complete form
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtComments")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtComments")).sendKeys("Cover Letter Testing");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtFirstName")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtFirstName")).sendKeys("Test");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtSecondName")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtSecondName")).sendKeys("Test");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtPhone")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtPhone")).sendKeys("12345678");
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtEmail")).clear();
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_txtEmail")).sendKeys("craig.mccarthy@live.ie");
// Upload CV not logged in
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_fileCV")).sendKeys("C:\\Users\\Craig\\Desktop\\CV_TEST.docx");
//wait for CV to upload
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//submit application
driver.findElement(By.id("ctl00_ctl00_cphMain_cphMain_ucApplyJob_btnSubmit")).click();
}

关于java - Selenium WebDriver 上传文件/关闭资源管理器窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19229686/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com