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
Selenium 变化的问题_Selenium - Fatal编程技术网

Selenium 变化的问题

Selenium 变化的问题,selenium,Selenium,我试图让Selenium自动运行多项选择题测试。然而,一对夫妇的问题可以改变为几个不同的事情。例如,问题可以是选择下面四个选项中的哪一个是猫。但是下次你运行测试时,可能会选择下面的那只狗。它只有几个问题需要改变 基本上,它会在第一个命令上停止,这与命令发出的时间不同。我明白为什么,但是,如果第一个选项不可用,有没有办法让它选择其他选项,这样我就可以在同一个命令中添加多个答案,它只需要找到其中一个就可以继续?我会将问题和正确答案构建一个哈希图,作为答案键,然后将页面上的问题与答案键进行比较选择正确

我试图让Selenium自动运行多项选择题测试。然而,一对夫妇的问题可以改变为几个不同的事情。例如,问题可以是选择下面四个选项中的哪一个是猫。但是下次你运行测试时,可能会选择下面的那只狗。它只有几个问题需要改变


基本上,它会在第一个命令上停止,这与命令发出的时间不同。我明白为什么,但是,如果第一个选项不可用,有没有办法让它选择其他选项,这样我就可以在同一个命令中添加多个答案,它只需要找到其中一个就可以继续?

我会将问题和正确答案构建一个哈希图,作为答案键,然后将页面上的问题与答案键进行比较选择正确的答案

HashMap<String, String> answerKey = new HashMap<>();
// you would likely read these from a CSV or maybe an Excel sheet
answerKey.put("Pick the one below that is a cat", "Felix");
answerKey.put("Pick the one below that is a dog", "Spot");


String question = driver.findElement(By.id("questionId")).getText().trim(); // some made up element that contains the question String.
String answer = answerKey.get(question); // look up the answer in the HashMap
// click the element that matches the 'answer' String
HashMap answerKey=newhashmap();
//您可能会从CSV或Excel表格中阅读这些内容
回答:放(“选择下面那只猫”,“菲利克斯”);
回答键。放置(“选择下面那只狗”,“斑点”);
String question=driver.findElement(By.id(“questionId”)).getText().trim();//某些组合元素包含问题字符串。
String answer=answerKey.get(问题);//在HashMap中查找答案
//单击与“答案”字符串匹配的元素