Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.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
C# 硒-按下数字键盘上的按钮(数字范围)_C#_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

C# 硒-按下数字键盘上的按钮(数字范围)

C# 硒-按下数字键盘上的按钮(数字范围),c#,selenium,selenium-webdriver,selenium-chromedriver,C#,Selenium,Selenium Webdriver,Selenium Chromedriver,我的程序中有数字触摸板(1-9),需要测试的是,当用户键入以结尾的数字时,检查是否:1到9,例如0,01/0,33/4,46,然后系统抛出通知:“无效价格” 数字只能在:5或0结束,然后才有可能付款 作为一个硒初学者,我不知道应该在那里做什么。我从这些字段中获取字符串值开始: var number1 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'

我的程序中有数字触摸板(1-9),需要测试的是,当用户键入以结尾的数字时,检查是否:1到9,例如0,01/0,33/4,46,然后系统抛出通知:“无效价格”

数字只能在:5或0结束,然后才有可能付款

作为一个硒初学者,我不知道应该在那里做什么。我从这些字段中获取字符串值开始:

        var number1 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'1')]")).Text;
        var number2 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'2')]")).Text;
        var number3 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'3')]")).Text;
        var number4 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'4')]")).Text;
        var number6 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'6')]")).Text;
        var number7 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'7')]")).Text;
        var number8 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'8')]")).Text;
        var number9 = driver.FindElement(By.XPath("//div[@class='numpad-button primary-button' and contains(.,'9')]")).Text;

有任何提示吗?

单击相关元素,尝试创建非法序列:

    WebElement number2 =
    driver.findElement(By.xpath(
           "//div[@class='numpad-button primary-button' and contains(.,'2')]"));
    WebElement quote = 
    driver.findElement(By.xpath(
          "//div[@class='numpad-button primary-button' and contains(.,',')]"));
    WebElement submit = 
    driver.findElement(By.xpath(
          "//div[@class='numpad-button primary-button' and contains(.,'submit')]"));

        // Test invalid price
        number2.click();
        number2.click();
        quote.click();
        number2.click();
        number2.click();
        submit.click();

        // Test expected exception here

代码是用Java编写的,因此需要您进行C#调整。

作为用户,我怎么知道我输入了无效的价格?通知是什么样子的?是页面上的红色文本还是弹出窗口?@JeffC当用户输入带有所述结尾的价格(如.0,01,3,14或3,12)并按下“支付”按钮时,屏幕上的上角会出现带有标签“无效价格”的弹出通知,并且没有任何内容添加到购物篮中。您想如何验证这一点?您是否输入随机数字,然后在单击“支付”之前检查字段中的内容,或者您是否输入特定的有效和无效价格,然后单击“支付”,然后检查是否出现弹出窗口?很遗憾,我无法使用它。我需要以某种方式做出if语句或类似的东西。在您的示例中,我如何做断言?您需要在输入无效价格后从UI捕获异常或错误消息。但首先,您必须成功地开发无效价格场景。你做到了吗?不是真的…..我能输入具体的数字,比如说3,14。然后这个数字在字段中,以后我可以使用“Text”功能获取值,然后我可能会以某种方式修剪数字以获得最后一个数字,最后创建“if”语句以检查数字是否以正确或不正确的结尾结束。这对您有意义吗:)?请用当前场景更新您的原始代码并添加异常消息