2017-02-16 49 views

回答

0

您可以使用XPath, 找到的XPath您可以使用本指南:

https://hedleyproctor.com/2011/05/tutorial-writing-xpath-selectors-for-selenium-tests/

看起來應該財產以後這樣的:

webDriver.findElement(
     By.xpath(
     "//*[@id="homeGetEnergy"]/div/div/form/div[3]/div[1]/input[1]" 
    ) 
    ).sendKeys("19082"); 

    webDriver.findElement(
     By.xpath(
     "//*[@id="homeGetEnergy"]/div/div/form/div[3]/div[1]/button/span/b/em" 
    ) 
    ).click(); 
+0

嗨,我完成了這些。點擊此表單提交後,您將獲得一個新表單,其中有一個沒有ID或名稱的下拉菜單。我什至嘗試使用xpath,它不工作。請幫助我。 –

0

試試下面的代碼這一點。

driver.get("https://www.directenergy.com/ny"); 
driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 

new Select(driver.findElement(By.xpath("//select[@name='goto_service_type']"))).selectByVisibleText("Natural Gas"); 
Thread.sleep(1000); 
driver.findElement(By.xpath("//input[@name='zipcode']")).sendKeys("19082"); 
driver.findElement(By.xpath("//button/span/b/em")).click(); 
Thread.sleep(8000); 

if(driver.getTitle().equals("Sign Up For Natural Gas In Pennsylvania | Direct Energy")) 
{ 
    System.out.println("Inside another page.."); 
} 
else 
{ 
    System.out.println("Redirection error."); 
} 
+0

嗨,我完成了這些。點擊此表單提交後,您將獲得一個新表單,其中有一個沒有ID或名稱的下拉菜單。我什至嘗試使用xpath,它不工作。請幫助我。 –

+0

我已經在我的端嘗試了這段代碼,它對我來說工作正常。執行上面的代碼時你有任何錯誤嗎?如果你得到請通過錯誤。 –

+0

如果此答案對您有幫助,請將此答案標記爲「已接受」。 –