這裏我想打印購物車中某些產品的動態生成的「運費」。 例如,在將商品添加到購物車後,在用戶輸入送貨地址後的結賬過程中,商店會動態生成運費。現在我想要打印運費。 編號=「數據結帳總出貨目標」如何使用Eclipes在硒中打印表單字段的動態生成值。
0
A
回答
1
@蘇里亞的答案是正確的。非常久遠的,你也可以嘗試下面的代碼,結果是:
String price = driver.findElement(By.xpath("//span[@class='total-line__name' and contains(text(),'Shipping')]/following-sibling::strong")).getText();
注: -在上面的代碼,你可以用替換的文字「運費」「小計」或「納稅'或'總計'太,以檢索他們各自的文本。
這裏,是更新的代碼,你詢問: -
public class Testing
{
public static void main(String args[]) throws InterruptedException{
WebDriver driver = new FirefoxDriver(); //Opening firefox instance
driver.manage().window().maximize(); //maximizing window
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); //Giving implicit timeout of 20 seconds
driver.get("http://testing-671.myshopify.com/"); //Navigating to url
driver.findElement(By.xpath("//img[@alt='testing']")).click(); //Clicking on Testing product
driver.findElement(By.xpath("//input[@id='add-to-cart']")).click(); //Clicking on Add to cart button
driver.findElement(By.xpath("//input[@id='checkout']")).click(); //Clicking on Checkout button
//Clearing and sending value in email
driver.findElement(By.xpath("//input[@id='checkout_email']")).clear();
driver.findElement(By.xpath("//input[@id='checkout_email']")).sendKeys("[email protected]");
//Clearing and sending value in first name
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_first_name']")).clear();
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_first_name']")).sendKeys("Test");
//Clearing and sending value in last name
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_last_name']")).clear();
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_last_name']")).sendKeys("Test");
//Clearing and sending value in address
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_address1']")).clear();
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_address1']")).sendKeys("Test Address");
//Clearing and sending value in city
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_city']")).clear();
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_city']")).sendKeys("Test City");
//Selecting India as Country
Select sel = new Select(driver.findElement(By.xpath("//select[@id='checkout_shipping_address_country']")));
sel.selectByVisibleText("India");
//Selecting Goa as Province
sel = new Select(driver.findElement(By.xpath("//select[@id='checkout_shipping_address_province']")));
sel.selectByVisibleText("Goa");
//Clearing and sending value in Zip
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_zip']")).clear();
driver.findElement(By.xpath("//input[@id='checkout_shipping_address_zip']")).sendKeys("789088");
//Clicking on Continue button
driver.findElement(By.xpath("//input[@value='Continue']")).click();
//Waiting till the text changes from "—" to some price value.
new WebDriverWait(driver,10).until(ExpectedConditions.invisibilityOfElementWithText(By.xpath("//span[@class='total-line__name' and contains(text(),'Shipping')]/following-sibling::strong"), "—"));
//Getting the price of Shipping
String price = driver.findElement(By.xpath("//span[@class='total-line__name' and contains(text(),'Shipping')]/following-sibling::strong")).getText();
//Printing price of shipping
System.out.println("The price of Shipping is: "+price);
}
1
試試這個代碼:
//Get the rate - updated with currect xpath
String rate = driver.findElement(By.xpath("//strong[@data-checkout-total-shipping-target]")).getText(); //shipping-option__price
//Print it in Eclipse console
System.out.println("Rate is " + rate);
相關問題
- 1. 流星動態表單字段生成
- 2. 如何在PHP的表單字段中打印數組值?
- 3. 從表單輸入中檢索字段值動態生成
- 4. 如何生成帶動態輸入的打印表格
- 5. 如何使用動態內容生成打印就緒格式?
- 6. 如何使用Java生成可打印(可保存)的表單?
- 7. 在數據庫上動態生成字段並生成表單的動態字段
- 8. 打印動態生成的PDF文件
- 9. 如何在JasperReport的表中水平地打印字段值
- 10. 動態表單字段自動完成
- 11. 如何用c#在Asp.net中生成動態模板字段?
- 12. 如何使用此動態生成的字段保存模型?
- 13. mySQL - 如何自動生成字段值
- 14. 讓瀏覽器記住動態生成表單中的輸入字段值
- 15. 如何使用Postgresql獲取自動生成的字段的值?
- 16. 硒RC(動態ID生成)
- 17. 如何在生成的動態字段中插入數據庫中的值
- 18. 如何在AngularJS的模板中使用動態生成的值
- 19. 在動態生成的字段中維護輸入值
- 20. 獲取動態表單字段的值
- 21. mvc4動態生成的字段從表單丟失
- 22. 如何選擇使用硒從下拉菜單動態生成的元素?
- 23. 在動態生成的字段中添加組字段名稱
- 24. PHP預打印使用動態用戶值打印的證書
- 25. 如何在Microsoft Access中打印動態表單?
- 26. 動態表單輸入字段和使用AJAX自動完成
- 27. 在JQuery中動態生成表單
- 28. 如何使用jQuery提交動態生成的表單?
- 29. Django/jQuery - 自動完成和動態更新表單字段值
- 30. 如何使用動態生成的ID選擇列表項 - 硒測試Python
嘿子,我試過你的代碼,但得到相同的「java.lang.NullPointerException」錯誤。 可以喲給我你運行的測試用例 – Ram 2014-11-25 08:48:16
@ user3159596:我已經添加了上面的代碼。請檢查。 – Subh 2014-11-25 10:25:44
嘿Subh,感謝您的代碼幫助。但我無法理解這段代碼。 所以我發佈了一個新的問題,我從selenium IDE獲得了完整的代碼,這裏是鏈接。給出格式,請幫助我解決這個問題。請編輯相同的代碼,讓我運行它們並獲得期望的結果。(能夠打印運費,即Rs 8) http://stackoverflow.com/questions/27124598/ – Ram 2014-11-25 10:52:52