有一個網站https://www.directenergy.com/ny,我需要從下拉菜單中選擇天然氣,並在郵政編碼文本框中輸入「19082」並點擊提交按鈕,我會得到一個新表單URL保持不變)。我需要知道如何識別這種新形式的網頁元素。我現在堅持使用新的頁面內容。請幫幫我。如何識別硒元素中的網絡元素
謝謝, Naveen。
有一個網站https://www.directenergy.com/ny,我需要從下拉菜單中選擇天然氣,並在郵政編碼文本框中輸入「19082」並點擊提交按鈕,我會得到一個新表單URL保持不變)。我需要知道如何識別這種新形式的網頁元素。我現在堅持使用新的頁面內容。請幫幫我。如何識別硒元素中的網絡元素
謝謝, Naveen。
您可以使用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();
嗨,我完成了這些。點擊此表單提交後,您將獲得一個新表單,其中有一個沒有ID或名稱的下拉菜單。我什至嘗試使用xpath,它不工作。請幫助我。 –
試試下面的代碼這一點。
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.");
}
嗨,我完成了這些。點擊此表單提交後,您將獲得一個新表單,其中有一個沒有ID或名稱的下拉菜單。我什至嘗試使用xpath,它不工作。請幫助我。 –
我已經在我的端嘗試了這段代碼,它對我來說工作正常。執行上面的代碼時你有任何錯誤嗎?如果你得到請通過錯誤。 –
如果此答案對您有幫助,請將此答案標記爲「已接受」。 –
看看http://selectorgadget.com/ – Rentrop