gpt4 book ai didi

java - 找到不可见的值

转载 作者:行者123 更新时间:2023-12-02 03:58:45 25 4
gpt4 key购买 nike

我有问题,我需要比较设置为我选择的货币的货币(左上角):

<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. 选择货币3. 最后,通过按空格分割,从货币名称中提取货币符号。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);
}

我希望这有帮助:)

关于java - 找到不可见的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35136346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com