Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在HashMap中放置两个web元素列表?_Java_Selenium - Fatal编程技术网

Java 如何在HashMap中放置两个web元素列表?

Java 如何在HashMap中放置两个web元素列表?,java,selenium,Java,Selenium,我有两个Selenium web元素列表。两个列表都包含字符串值。如何将它们放入哈希映射中,验证是否存在“上一个金额”和“总金额”,并且它们的精度都为2 桌子 我目前编写了以下代码: @FindBy(How=How.Xpath, using =“xpath to header”) private static List<WebElement> header; @FindBy(how=How.Xpath, using =“xpath to headerValue”) private

我有两个Selenium web元素列表。两个列表都包含字符串值。如何将它们放入哈希映射中,验证是否存在“上一个金额”和“总金额”,并且它们的精度都为2

桌子

我目前编写了以下代码:

@FindBy(How=How.Xpath, using =“xpath to header”)
private static List<WebElement> header;

@FindBy(how=How.Xpath, using =“xpath to headerValue”)
private static List<WebElement> headerValue;

public HasMap<String,String> verifyHeaderAndValue()
{
    HasMap<String,String> hedDetails = new HasMap<>();
    for(int I = 0; I < hedDetails.size(); I++)
    {
        hedDetails.put(header.get(I).getText(), headerValue.get(I).getText());
    }
    return hedDetails;
}
@FindBy(How=How.Xpath,使用=“Xpath to header”)
私有静态列表头;
@FindBy(how=how.Xpath,使用=“Xpath to headerValue”)
私有静态列表头值;
public HasMap verifyHeaderAndValue()
{
HasMap hedDetails=新的HasMap();
对于(int I=0;I
您的代码中有一些打字错误,因此无法编译。我已经把下面的修好了

@FindBy(how = How.XPATH, using = "")
private static List<WebElement> header;

@FindBy(how = How.XPATH, using = "")
private static List<WebElement> headerValue;

此处为以前金额的值控制代码,对于总金额,您可以使用相同的值控制代码(TestNG资产):


List
不包含
String
s,它包含
WebElement
。您是指元素内部的文本,例如
元素.getText()
?听起来你是在描述你对这个问题的解决方案。我建议你先描述问题,然后再描述你试图解决问题的方法。有时,有更好或更有效的方法来完成您正在尝试的操作,但如果您没有很好地描述原始问题,我们将尝试修复您的方法,而不是提供更好的方法。您好,感谢您的快速重播。是的,我指的是Web元素内部字符串。我试过以上的解决办法。但我想验证是否有带有web表值的映射。web元素的标题列表包含标题列表,元素的值列表包含值列表。我想验证该值是否为空。请花几分钟时间修复代码。有多个打字错误和语法问题。如果你能回答,我会稍微更新我的问题杰夫,你已经创建了一个全新的问题来问同样的问题。你需要删除这个新问题,编辑这个问题并添加新的信息。当然我现在就要删除它。有没有一种方法可以拆分为“.”并检查该值的精度是否为2?@JeffC“^\\d+\.\\d{2}$”和“\\d+\.\\d{2}$”对我不起作用,但是“\d+.\d{2}$”对我不起作用。@theGuy奇怪,idea说“嗨,当我尝试上面的代码时,字符串值是空的。我认为字符串prevAmount=headerDetails.get(“previousAmount”);无法正常工作。请在填充hashmap打印键和值后@Sersaft帮助我解决此问题。让我看看是否正确
public HashMap<String, String> getHeaderAndValue()
{
    // need to make sure that the two element lists are the same size or the comparison should/will fail
    Assert.assertEquals(header.size(), headerValue.size());

    HashMap<String, String> headDetails = new HashMap<>();
    for (int i = 0; i < header.size(); i++)
    {
        headDetails.put(header.get(i).getText(), headerValue.get(i).getText());
    }

    return headDetails;
}
String prevAmount = headDetails.get("Previous Amount");
Assert.assertNotNull(prevAmount, "Previous Amount found");
//if amount can NOT be negative
Assert.assertTrue(prevAmount.matches("^\\d+\\.\\d{2}$"), "Has 2 precision");
//if amount can be negative
Assert.assertTrue(prevAmount.matches("\\d+\\.\\d{2}$"), "Has 2 precision");