寻找不可见的价值
Find value which is not visible
我有问题我需要比较设置为我选择的货币的货币(左上角):
<div class="btn-group">
<button class="btn btn-link dropdown-toggle" data-toggle="dropdown">
<strong>£</strong>
<span class="hidden-xs hidden-sm hidden-md">Currency</span> <i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu">
<li><button class="currency-select btn btn-link btn-block" type="button" name="EUR">€ Euro</button></li>
<li><button class="currency-select btn btn-link btn-block" type="button" name="GBP">£ Pound Sterling</button></li>
<li><button class="currency-select btn btn-link btn-block" type="button" name="USD">$ US Dollar</button></li>
</ul>
</div>
这里我选择货币:
public void setCurrency(String currencyToSet){
WebElement currencyVal= driver.findElement(By.name(currencyToSet.toUpperCase()));
currencyVal.click();
}
我不知道如何比较我选择的货币与设置的货币。
它应该是这样的:demo.opencart.com
我的假设是 - 您首先要设置货币为“欧元欧元”,然后您要通过验证货币符号来检查是否设置了“欧元欧元”。
所以,你能做的是——
1. 在选择之前获取货币名称,将其存储在变量中。
2. Select 货币
3. 最后,通过将货币名称拆分为 space,从货币名称中提取货币符号。
4. 现在,有了货币符号,您可以轻松地将其与设置的内容进行比较。
这是 C# 代码
[Test]
public void Test3()
{
string currencyToSet = "EUR";
IWebElement currencyDropDown = driver.FindElement(By.CssSelector("button[class='btn btn-link dropdown-toggle']"));
currencyDropDown.Click();
//Locate the Currency
IWebElement currencyVal = driver.FindElement(By.Name(currencyToSet.ToUpper()));
//Before clicking Currency, store Currency Name in a variable.
string currencyName = currencyVal.Text;
//Print Currency Name
Console.WriteLine("Currency Name:" + currencyName);
//Click on Currency
currencyVal.Click();
//Extract Currency Symbol from Currency Name
string[] spittedCurrencyName = currencyName.Split(' ');
string currencySymbol = spittedCurrencyName[0];
//Now you have Currency Symbol. Therefore, you can easily compare it with what is set.
Console.WriteLine("Currency Symbole: " + currencySymbol);
}
希望对您有所帮助:)
这对我有用。希望对你有帮助。
driver.get("http://demo.opencart.com/");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.xpath("//button[@class='btn btn-link dropdown-toggle']")).click();
//WebElement selectCurrency = driver.findElement(By.xpath("//button[@name='USD']"));
//WebElement selectCurrency = driver.findElement(By.xpath("//button[@name='GBP']"));
WebElement selectCurrency = driver.findElement(By.xpath("//button[@name='EUR']"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", selectCurrency);
String[] currency = driver.findElement(By.xpath("//div[@id='cart']//span")).getText().split("- ");
String[] c1 = currency[1].split("0.00");
System.out.println(currency[1]);
System.out.println(c1[0]);
if(c1[0].equalsIgnoreCase("$"))
{
System.out.println("Doller selected");
}
else if(c1[0].equalsIgnoreCase("£"))
{
System.out.println("Pound");
}
else if(c1[1].equalsIgnoreCase("€"))
{
System.out.println("Euro");
}
我有问题我需要比较设置为我选择的货币的货币(左上角):
<div class="btn-group">
<button class="btn btn-link dropdown-toggle" data-toggle="dropdown">
<strong>£</strong>
<span class="hidden-xs hidden-sm hidden-md">Currency</span> <i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu">
<li><button class="currency-select btn btn-link btn-block" type="button" name="EUR">€ Euro</button></li>
<li><button class="currency-select btn btn-link btn-block" type="button" name="GBP">£ Pound Sterling</button></li>
<li><button class="currency-select btn btn-link btn-block" type="button" name="USD">$ US Dollar</button></li>
</ul>
</div>
这里我选择货币:
public void setCurrency(String currencyToSet){
WebElement currencyVal= driver.findElement(By.name(currencyToSet.toUpperCase()));
currencyVal.click();
}
我不知道如何比较我选择的货币与设置的货币。
它应该是这样的:demo.opencart.com
我的假设是 - 您首先要设置货币为“欧元欧元”,然后您要通过验证货币符号来检查是否设置了“欧元欧元”。
所以,你能做的是—— 1. 在选择之前获取货币名称,将其存储在变量中。 2. Select 货币 3. 最后,通过将货币名称拆分为 space,从货币名称中提取货币符号。 4. 现在,有了货币符号,您可以轻松地将其与设置的内容进行比较。
这是 C# 代码
[Test]
public void Test3()
{
string currencyToSet = "EUR";
IWebElement currencyDropDown = driver.FindElement(By.CssSelector("button[class='btn btn-link dropdown-toggle']"));
currencyDropDown.Click();
//Locate the Currency
IWebElement currencyVal = driver.FindElement(By.Name(currencyToSet.ToUpper()));
//Before clicking Currency, store Currency Name in a variable.
string currencyName = currencyVal.Text;
//Print Currency Name
Console.WriteLine("Currency Name:" + currencyName);
//Click on Currency
currencyVal.Click();
//Extract Currency Symbol from Currency Name
string[] spittedCurrencyName = currencyName.Split(' ');
string currencySymbol = spittedCurrencyName[0];
//Now you have Currency Symbol. Therefore, you can easily compare it with what is set.
Console.WriteLine("Currency Symbole: " + currencySymbol);
}
希望对您有所帮助:)
这对我有用。希望对你有帮助。
driver.get("http://demo.opencart.com/");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.xpath("//button[@class='btn btn-link dropdown-toggle']")).click();
//WebElement selectCurrency = driver.findElement(By.xpath("//button[@name='USD']"));
//WebElement selectCurrency = driver.findElement(By.xpath("//button[@name='GBP']"));
WebElement selectCurrency = driver.findElement(By.xpath("//button[@name='EUR']"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", selectCurrency);
String[] currency = driver.findElement(By.xpath("//div[@id='cart']//span")).getText().split("- ");
String[] c1 = currency[1].split("0.00");
System.out.println(currency[1]);
System.out.println(c1[0]);
if(c1[0].equalsIgnoreCase("$"))
{
System.out.println("Doller selected");
}
else if(c1[0].equalsIgnoreCase("£"))
{
System.out.println("Pound");
}
else if(c1[1].equalsIgnoreCase("€"))
{
System.out.println("Euro");
}