【问题标题】:Couple Things With Selenium与硒结合的东西
【发布时间】:2014-12-11 03:21:30
【问题描述】:

我一直在与 Selenium 和 Fiverr.com 合作,遇到了一些问题,希望能得到一些帮助。我正在尝试创建一个新的演出,并且我已经设法完成了所有事情,但有些事情仍然困扰着我。一件事是图片上传。

• 您有一个按钮,您单击文件输入类型 () 会弹出一个 Windows 对话框,到目前为止,我使用 SendKeys.SendWait 的计划已经奏效,除了在 Windows 对话框上按“打开”的部分提交图片。我试过使用 SendKeys.SendWait("{ENTER}") 来点击它,但到目前为止这对我没有用,所以有什么想法吗?除非 P/Invoke 可以处理 Windows 对话框,否则我想不出任何其他方法?

•我也在尝试在“描述”框中输入文本,但还不能这样做。我试图通过类名来获取它,但它告诉我它无法访问该类,因为它是隐藏的,还尝试通过 Javascript (IJavaScriptExecutor) 像这样:

    IWebElement detailFrame = firefoxDriver.FindElement(By.XPath("/html/body"));
    var executor = firefoxDriver as IJavaScriptExecutor;
    executor.ExecuteScript("arguments[0].innerHTML = 'hiiiiiiii'", detailFrame); 

这很奇怪,因为他们将正文用于文本字段,如下所示:

<body marginwidth="0" marginheight="0" spellcheck="true" class="wysihtml5-editor" contenteditable="true" style="color: rgb(119, 119, 119); cursor: auto; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; letter-spacing: normal; text-align: start; text-decoration: none; text-indent: 0px; text-rendering: auto; word-break: normal; word-wrap: break-word; word-spacing: 0px; overflow: auto; background-color: rgb(255, 255, 255);">TEXT HERE<span id="_wysihtml5-undo" class="_wysihtml5-temp"></span></body>

我认为他们使用了两个不同的“body”,但 XPath 只是显示它是 /html/body。我该如何设置这样的文本?

谢谢你们的帮助,过去两个小时一直在做这个。

【问题讨论】:

    标签: c# selenium


    【解决方案1】:
    1. Selenium 具有处理窗口的机制。您可以使用driver.SwitchTo().Window(""); 将焦点设置在新打开的窗口上并对其执行其他操作。但是,请记住,要返回父窗口,您可能需要再次使用 默认内容。有关其他窗口处理技术,请参阅here

    2. 首先,selenium 无法识别隐藏元素。如果您确定该元素没有隐藏,那么我可能会说您使用的选择器可能不正确。如果我清楚地理解您提供的 html 并且该元素是可见的,那么我建议您对该元素使用 xpath。 //*[@id='_wysihtml5-undo']//.. 对你有帮助

    【讨论】:

    • 告诉我无法找到元素(_wysihtml5-undo),我已经通过 XPath 和 ID 尝试过,有什么想法吗?
    • 您能准确告诉我您要执行的步骤吗?
    • firefoxDriver.FindElementById("_wysihtml5-undo").SendKeys("Hi");或 firefoxDriver.FindElementByXPath("//*[@id='_wysihtml5-undo']").SendKeys("Hi");两者都抛出未找到的相同错误。
    • 你从来没有提到过 iframe。所以我自动认为你正在处理新打开的窗口。很高兴帮助
    猜你喜欢
    • 2011-04-05
    • 1970-01-01
    • 2010-09-05
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    相关资源
    最近更新 更多