2017-04-09 91 views
0

下面是我的代码,这是我在练习Selenium webdriver时写的。在下面的代码linkText没有获取所需的值。完成之前有关同一问题的答案中提供的所有内容。Linktext不能正常工作

package newpackage; 
import org.openqa.selenium.*; 
import org.openqa.selenium.ie.InternetExplorerDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 

public class PG9 { 
    public static void main(String[] args) { 
     System.setProperty("webdriver.ie.driver","D:\\Tools & Utilities\\IEDriverServer_x64_3.3.0\\IEDriverServer.exe"); 
     InternetExplorerDriver driver = new InternetExplorerDriver(); 
     String baseUrl = "http://www.monsterindia.com"; 
     //WebDriverWait myWaitVar = new WebDriverWait(driver, 50); 
     driver.get(baseUrl); 
     //myWaitVar.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.linkText("Upload Resume"))); 

     driver.findElement(By.linkText("Upload Resume")).click(); 

     String expectedTitle = "Job Search | Job Vacancies | Job Opportunities in India | Monster India"; 
     String actualTitle = ""; 
     actualTitle = driver.getTitle(); 

     /* 
     * compare the actual title of the page with the expected one and print 
     * the result as "Passed" or "Failed" 
     */ 
      if (actualTitle.contentEquals(expectedTitle)){ 
       driver.findElement(By.id("name")).sendKeys("Abhay Dadhkar"); 
       driver.findElement(By.id("mob_no")).sendKeys("9011134418"); 
       driver.findElement(By.id("wordresume")).sendKeys("D:\\Abhay\\Abhay_Training_Profile\\Training_Profile\\AbhayDadhkar_Detail_Profile_Jan2017.docx"); 
      } else 
      { 
       System.out.println("Test Failed"); 
      } 
    driver.close(); 

     // enter the file path onto the file-selection input field 
     WebElement uploadElement = driver.findElement(By.name("File name")); 
     uploadElement.sendKeys("D:\\Automation tools\\Selenium\\Selenium_Practice\\newhtml.html"); 

     // check the "I accept the terms of service" check box 
     //driver.findElement(By.name("Open")).click(); 

     // click the "UploadFile" button 
     driver.findElement(By.name("Open")).click(); 
     } 

} 
+0

使用'driver.findElement(By.id( “jobuser_wrap”))点击()。相反 – kushal

回答

0

By.linkText<a>标签的作品。如果您想通过文字来查找使用xpath代替

driver.findElement(By.xpath("//span[contains(., 'Upload Resume')]")).click(); 

您也可以单击父<div>

driver.findElement(By.className("fileUpload")).click();