我从selenium和java开始。我正在试验这个https://www.argenta.nl/hypotheek/hypotheek-berekenen#/formulier网站。 (这是一个抵押贷款计算器)我陷入了必须选择我的工作(dienstverband)并填写收入金额(bruto jaarinkomen)并点击“ga verder”按钮的地步。
按钮'ga verder'验证字段收入是否已填满。在我的脚本中,我用这行代码填写此字段“收入”:
driver.findElement(By.name("orientationCalculatorCtrlCalculatorMainApplicantIncomePermanentThisYearIncome")).sendKeys("51000");
但是,当我点击按钮'ga verder'时,没有任何内容被填充。(系统发出红色通知)我认为发送密钥是填写所需文本字段的正确选项。谁能帮助我。
我的整个测试文件:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Esmee\\IdeaProjects\\seleniumTestArgenta\\src\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.argenta.nl");
WebElement element;
//opening orientation calculator (code akkoord)
driver.findElement(By.xpath("/html/body/div/header/div/div/div[3]/ul/li[2]/a")).click();
driver.findElement(By.xpath("/html/body/div/header/div/div/div[3]/ul/li[2]/div/div/div/a[2]/div[1]")).click();
driver.findElement(By.xpath("/html/body/div/div[2]/article[1]/div/div/div/div[2]/div/div/a")).click();
//wait for 10 seconds
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//clicking on button 'ga verder'gives a notification (Code Akkoord)
driver.findElement(By.xpath("/html/body/div/div[2]/article[1]/div/form/div/ui-view[1]/div/div/div[2]/div/button")).click();
//Uw situatie, select radiobutton no (= value 1 ), then push button 'ga verder'.
element = driver.findElement(By.cssSelector("input[value='1']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
driver.findElement(By.xpath("/html/body/div/div[2]/article[1]/div/form/div/ui-view[1]/div/div/div[2]/div/button")).click();
//wait for page to load, select income, fill in 51000
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"orientationCalculatorCtrlCalculatorMainApplicantIncomeVariant\"]"));
Select dropdown = new Select(driver.findElement(By.id("orientationCalculatorCtrlCalculatorMainApplicantIncomeVariant")));
dropdown.selectByVisibleText("Vast contract");
driver.findElement(By.name("orientationCalculatorCtrlCalculatorMainApplicantIncomePermanentThisYearIncome")).sendKeys("51000");
//pushing button 'ga verder' (system verifies input)
element = driver.findElement(By.xpath("/html/body/div/div[2]/article[1]/div/form/div/ui-view[2]/div/div/div[2]/div/button"));
executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();",element);
答案 0 :(得分:0)
你可以尝试:
WebElement yourElement = driver.findElement(By.xpath("nameOfTheElementHere"));
Actions act = new Actions(driver);
act.moveToElement(yourElement).click();
act.sendKeys("51000");
act.build().perform();
或者:
WebElement yourElement = driver.findElement(By.xpath("xpathHere"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", yourElement);
或者它可能只是一个等待问题,在这种情况下:
WebElement yourElement = driver.findElement(By.xpath("xpathHere"));
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(yourElement)).click();