[英]For Loop C# issue
我想實現一個簡單的循環,該循環不斷進行迭代,直到達到200的值為止。
但是,在我有i =初始值的情況下,我希望它使用以下XPath string totalPrice = webDriver.FindElement(By.XPath("//span[@class='bag-subtotal-price']")).Text;
進行拉取string totalPrice = webDriver.FindElement(By.XPath("//span[@class='bag-subtotal-price']")).Text;
所以我實際上不會設置值,它會根據項目是動態的。
然后,我想通過增加袋子的數量來增加循環,直到達到200。
為了增加數量的價值,我需要使用以下XPath
IWebElement qty = webDriver.FindElement(By.XPath(
"//select[contains(@class,'bag-item-quantity')]"));
SelectElementFromDropDown(qty, Math.Floor(noOfQuantity).ToString());
wait.Until(ExpectedConditions.ElementExists(By.XPath(
"//button[@class='bag-item-edit-update']")));
webDriver.FindElement(By.XPath(
"//button[@class='bag-item-edit-update']")).Click();
有沒有一種方法可以從XPath調用值,而不是對其進行硬編碼?
public void Main()
{
for (int i = 120; i <= 200; i++)
{
我會轉一段while
循環:
string strTotalPrice = webDriver.FindElement(By.XPath("//span[@class='bag-subtotal-price']")).Text;
int totalPrice = Convert.ToInt32(strTotalPrice);
while(totalPrice <= 200)
{
// whatever code that increases totalPrice's value
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.