Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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
Java 在iframe内部的可编辑div中写入_Java_Html_Iframe_Selenium Webdriver - Fatal编程技术网

Java 在iframe内部的可编辑div中写入

Java 在iframe内部的可编辑div中写入,java,html,iframe,selenium-webdriver,Java,Html,Iframe,Selenium Webdriver,切换到iframe driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ContentFrame']"))); 我试过这两种方法,但都不管用 行动: WebElement webElement = driver.findElement(locator); action().moveToElement(webElement); action().click(); a

切换到
iframe

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ContentFrame']")));
我试过这两种方法,但都不管用

行动:

WebElement webElement = driver.findElement(locator);
        action().moveToElement(webElement); 
        action().click();
        action().sendKeys("Hello world");
        action().build().perform();
<iframe id="ContentFrame" width="100%" height="500" frameborder="0" allowfullscreen="" src="/content/geometrixx/assdasasda.html" style="height: 603px;">
<!DOCTYPE html>
    <html class=" aem-AuthorLayer-Edit" style="overflow: hidden;">
      <head>
      <body class="page homepage " spellcheck="false">
           <div class="parbase clientcontext">
           <div id="main_bg" class="bg">
               <div class="header">
               <div id="main">
                   <div class="container_16">
                        <div class="grid_16">
                        <div class="grid_12 body_container">
                             <div class="lead">
                             <div class="par parsys">
                                   <div class="section text parbase is-edited gecko" contenteditable="true" style="outline-style: none;">
                                   <p>Hello World</p>
JS执行人

WebElement webElement = driver.findElement(locator);
        String script = "arguments[0].setAttribute('value', 'Hello world');";
        ((JavascriptExecutor) driver).executeScript(script, webElement);
HTML:

WebElement webElement = driver.findElement(locator);
        action().moveToElement(webElement); 
        action().click();
        action().sendKeys("Hello world");
        action().build().perform();
<iframe id="ContentFrame" width="100%" height="500" frameborder="0" allowfullscreen="" src="/content/geometrixx/assdasasda.html" style="height: 603px;">
<!DOCTYPE html>
    <html class=" aem-AuthorLayer-Edit" style="overflow: hidden;">
      <head>
      <body class="page homepage " spellcheck="false">
           <div class="parbase clientcontext">
           <div id="main_bg" class="bg">
               <div class="header">
               <div id="main">
                   <div class="container_16">
                        <div class="grid_16">
                        <div class="grid_12 body_container">
                             <div class="lead">
                             <div class="par parsys">
                                   <div class="section text parbase is-edited gecko" contenteditable="true" style="outline-style: none;">
                                   <p>Hello World</p>

你好,世界


要在框架内编写,您需要单击
框架主体
,然后可以编写任何您想要的内容

方法1

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ContentFrame']")));
WebElement framebody = driver.findElement(By.tagName("body"));
new Actions(driver).click(framebody).sendKeys("Hello World!").build().perform();
方法2

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ContentFrame']")));
WebElement framebody = driver.findElement(By.tagName("body"));
framebody.sendKeys("HelloWorld!");

希望它能起作用。

要在框架内编写,您需要单击
framebody
,然后可以编写任何您想要的内容

方法1

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ContentFrame']")));
WebElement framebody = driver.findElement(By.tagName("body"));
new Actions(driver).click(framebody).sendKeys("Hello World!").build().perform();
方法2

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ContentFrame']")));
WebElement framebody = driver.findElement(By.tagName("body"));
framebody.sendKeys("HelloWorld!");

希望它能起作用。

您是否尝试过只发送密钥而不使用
操作
<代码>webElement.sendKeys(“Hello world”)。有时最简单的方法效果最好。您是否尝试过只发送密钥而不使用
操作
<代码>webElement.sendKeys(“Hello world”)。有时候,最简单的方法效果最好。它奏效了。但是如果我想验证这个文本“Hello World!”或者点击它。我尝试先单击
framebody
,然后通过.xpath(//div[@class='text cq dd image']/p[contains(text(),'Hello World!']))单击类似这样的文本
但它不起作用,并给出了一些其他元素收到的错误。我在firepath中看不到它(因为它在同一个iframe中),但可以在HTML控制台中看到它。它成功了。但是如果我想验证这个文本“Hello World!”或者点击它。我尝试先单击
framebody
,然后通过.xpath(//div[@class='text cq dd image']/p[contains(text(),'Hello World!']))单击类似这样的文本
但它不起作用,并给出了一些其他元素收到的错误。我不能在firepath中看到它(因为它在同一个iframe中),但可以在HTML控制台中看到它。