【问题标题】:Entering text to a <p> tag with selenium C#使用 selenium C# 将文本输入到 <p> 标记
【发布时间】:2016-03-09 14:19:57
【问题描述】:

我花了大约最后一个小时试图在屏幕上找到一个元素来添加文本。我已经处理了标题,但似乎无法添加正文。

<body id="tinymce" class="mce-content-body content post-type-post post-status-auto-draft post-format-standard locale-en mceContentBody wp-editor wp-autoresize html5-captions has-focus" contenteditable="true" data-id="content" style="overflow-y: hidden;">
    <p>
        <br data-mce-bogus="1">
    </p>

当我搜索元素时,它会将我定向到&lt;p&gt; 标签。
我被难住了。

driver.FindElement(By.Id("tinymce")).SendKeys("Lorem ipsum dolor sit amet, consectetur adipiscing elit");

【问题讨论】:

  • 感谢您提供的链接,如果我说实话,请努力关注它。我似乎遇到了同样的问题,但是我似乎无法在 wordpress 上找到添加帖子的正文。

标签: c# selenium


【解决方案1】:

您可以通过以下方式做到这一点。只需将语法更改为 java 中的代码

driver.findElement(By.id("tinymce")).findElement(By.tagName("p")).sendKeys("Lorem ipsum dolor sit amet, consectetur adipiscing elit");

希望对你有帮助:)

【讨论】:

  • 目前似乎没有找到“tinymce”,但它运行良好
  • @Peter 那是因为 iframe,它很可能在你需要切换到的 iframe 中。
  • @alecxe 我不知道这意味着什么?我对这一切都很陌生。
  • driver.switchTo().frame(0); ..他的意思是说先打开框架,然后使用我的代码....阅读框架切换..有很多方法可以切换到框架
  • driver.SwitchTo().Frame(driver.FindElement(By.Id("tinymce")).FindElement(By.TagName("p")).SendKeys("Lorem ipsum dolor sit amet , consectetur adipiscing elit"));现在出现了2个错误。我显然还没有得到它。
【解决方案2】:

做到了。在这种情况下,这是我的解决方法。这几乎与你们所说的经过一些调整。

        driver.SwitchTo().Frame(driver.FindElement(By.Id("content_ifr")));
        driver.FindElement(By.Id("tinymce")).SendKeys("your data");

【讨论】:

    猜你喜欢
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 2021-04-19
    • 2020-10-30
    • 1970-01-01
    相关资源
    最近更新 更多