簡體   English   中英

Selenium WebDriver上傳文件/關閉資源管理器窗口

[英]Selenium WebDriver upload file/close explorer window

我在上傳文件和關閉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,我可以暫停測試並等待CV上傳。

Applyjob.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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM