Selenium 如何验证在新表单中输入的值是否正确反映在编辑表单中
我试图自动化一个网站,主要是处理表单。我已经在新表单中输入了值,我需要验证它是否正确反映在编辑表单中。 以新的形式,我尝试了如下方式:Selenium 如何验证在新表单中输入的值是否正确反映在编辑表单中,selenium,Selenium,我试图自动化一个网站,主要是处理表单。我已经在新表单中输入了值,我需要验证它是否正确反映在编辑表单中。 以新的形式,我尝试了如下方式: WebElement FN = driver.findElement(By.id("ctl00_ctl41_g_1fc852c8_32cb_4220_80ee_2af21b671f9e_ff21_ctl00_ctl00_TextField")); FN.click(); FN.sendKeys("abc"); 在编辑表单代码中: if(FN.getAt
WebElement FN = driver.findElement(By.id("ctl00_ctl41_g_1fc852c8_32cb_4220_80ee_2af21b671f9e_ff21_ctl00_ctl00_TextField"));
FN.click();
FN.sendKeys("abc");
在编辑表单代码中:
if(FN.getAttribute("value").equals("abc"))
System.out.println("First Name is matching with new form");
else
System.out.println("First Name is not matching with new form");
我得到了这样的错误
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document(Session info: chrome=57.0.2987.110)
提前感谢。您可能在
FN.sendKeys(“abc”)出现异常代码>
。在进入编辑模式之前单击图元时,该图元也在更改。这就是为什么你会有这样的例外
我建议,在单击FN元素后,重新为textfield设置定位器,并在其上使用sendkeys()
方法
要了解此类型的异常,这可能会帮助您:
在编辑表单时,您需要重新初始化FNWebelement,因为一旦您离开新表单,以前的FNWebelement就会过时。因此,请尝试以下操作:
FN = driver.findElement(By.id("ctl00_ctl41_g_1fc852c8_32cb_4220_80ee_2af21b671f9e_ff21_ctl00_ctl00_TextField"));
if(FN.getAttribute("value").equals("abc"))
System.out.println("First Name is matching with new form");
else
System.out.println("First Name is not matching with new form");
如果您有任何进一步的疑问,请告诉我。您阅读了吗?