无法在文本框中输入文本

时间:2018-08-13 05:30:45

标签: java selenium selenium-webdriver

我正在尝试使FeeCRM网站自动化。登录到应用程序后,单击 Forms-> New Form ,由于Xpath问题,我无法在Title字段中输入文本,我也使用了框架。我仍然无法找到问题。请帮我写代码。 网址https://docs.databricks.com/api/latest/clusters.html#start 我的代码

driver.get("https://www.freecrm.com/index.html");
driver.findElement(By.name("username")).sendKeys("XXXXX");
driver.findElement(By.name("password")).sendKeys("XXXXX");
driver.findElement(By.xpath("//input[@class='btn btn-small']")).click();
WebDriverWait wait=new WebDriverWait(driver,20);
driver.switchTo().frame("mainpanel");
WebElement Form=driver.findElement(By.xpath("//div[@id='navmenu']/ul/li[14]"));
Actions action=new Actions(driver);
action.moveToElement(Form).build().perform();
//driver.findElement(By.xpath("//ul//li[14]//li[1]")).click();
String FormName=driver.findElement(By.xpath("//a[@title='New Form']")).getText();
System.out.println(FormName);
Assertion.assertEquals(FormName,"New Form");
driver.findElement(By.xpath("//a[@title='New Form']")).click();
WebDriverWait w=new WebDriverWait(driver,30);
//driver.switchTo().frame("mainpanel");
//String F1=driver.findElement(By.xpath("//fieldset[@class='fieldset']")).getText();
//  Assertion.assertEquals(F1,"Feedback form");
driver.findElement(By.xpath("//form[@id='feedbackForm']//table//tr[1]//td[2]//input")).sendKeys("Enter Form Name");

1 个答案:

答案 0 :(得分:0)

我的建议紧急改善您的代码风格,定位符... 也许使用某些框架会更好,请尝试Selenide http://selenide.org/

WebDriverWait wait = new WebDriverWait(driver, 20);

driver.findElement(By.name("username")).sendKeys("XXXXX");
driver.findElement(By.name("password")).sendKeys("XXXXX");
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[value='Login']"))).click();

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("mainpanel")));

new Actions(driver)
        .moveToElement(driver.findElement(By.cssSelector("a[title='Forms']")))
        .build().perform();
driver.findElement(By.cssSelector("a[title='New Form']")).click();

driver.findElement(By.id("title")).sendKeys("my title");