我有以下HTML
<div class="t-beaneditor-row">
<label>Login ID</label>
SeleniumReset
</div>
Run Code Online (Sandbox Code Playgroud)
我想使用WebDriver Java从HTML中检索字符串"SeleniumReset".我试过了
driver.findElement(By.xpath("//div")).getText()
Run Code Online (Sandbox Code Playgroud)
但它给了我"登录ID SeleniumReset".如何只检索"SeleniumReset"?
我面临以下问题.我无法在iframe中输入文本编辑器中的文本:这是html:
<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" style="width: 100%; height: 100%;" aria-describedby="cke_39" title="??????? ???????? ?? ?????????? ?????,description1" src="" tabindex="0" allowtransparency="true">
<!DOCTYPE html>
<html lang="bg" dir="ltr">
<head>
<body class="cke_editable cke_editable_themed cke_contents_ltr" contenteditable="true" spellcheck="false">
<p>
<br>
</p>
</body>
</html>
</iframe>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所做的,但测试成功通过,文本编辑器中没有写入任何文本.可能解决方案是使用Javascript执行程序,但我不熟悉它.
WaitTool.waitForElementPresent(Browser.instance, By.tagName("iframe"), 10);
WebElement iframe = Browser.instance.findElement(By.tagName("iframe"));
Browser.instance.switchTo().frame(iframe);
WebElement description=Browser.instance.findElement(By.xpath("//body[@class='cke_editable cke_editable_themed cke_contents_ltr']"));
description.click();
description.sendKeys("someText");
Browser.instance.switchTo().defaultContent();
Run Code Online (Sandbox Code Playgroud)
提前致谢!
Selenium 2.42.2 webdriver与Firefox 27.0.1兼容吗?如果没有,那么它兼容哪个Firefox版本?我正在使用Selenium 2.42.2 webdriver.我写的测试代码是:
public class SeleniumIntro {
/**
* @param args
*/
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println(driver.getCurrentUrl() + " "
+ driver.getPageSource());
driver.close();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,Firefox启动,然后没有任何反应.我有预感它的兼容性问题.顺便说一下,我也尝试过最新版本的Firefox,但效果相同.我可以在这里使用一些帮助或指导.谢谢.
我希望能够验证(或断言)存在类("框").
我可以用Selenium IDE做到这一点吗?
这是一个使用类"box"的html示例
...
<div class="box documentText">
...
</div>
...
Run Code Online (Sandbox Code Playgroud)
如何验证页面是否包含此类"框"?
driver.findElement(By.xpath("//input[@type="+"checkbox"+"]/following-sibling:://td[contains(text(),"+"template"+"]"))
Run Code Online (Sandbox Code Playgroud)
我的HTML就像这样
<tr>
<td class="tablecontent">
<input type="checkbox" value="59781" name="templateIds">
</td>`enter code here`
<td class="tablecontent"> test11 </td>
</tr>
Run Code Online (Sandbox Code Playgroud)
org.openqa.selenium.InvalidSelectorException:给定的选择器//输入[@type = checkbox]/following-sibling :: // td [contains(text(),template]无效或不会产生WebElement.发生以下错误:InvalidSelectorError:由于以下错误,无法找到具有xpath表达式的元素//输入[@type = checkbox]/following-sibling :: // td [contains(text(),template]:[Exception] ..."表达式不是合法表达式."代码:"12"nsresult:"0x805b0033(SyntaxError)"location:"file:/// C:/ Users/sanjdash/AppData/Local/Temp/anonymous3529970525380845680webdriver-profile /extensions/fxdriver@googlecode.com/components/driver_component.js行:5956"]命令持续时间或超时:72毫秒有关此错误的文档,请访问: http://seleniumhq.org/exceptions/invalid_selector_exception.html构建信息:版本:'2.37.0',修订版:'a7c61cbd68657e133ae96672cf995890bad2ee42',时间:'2013-10-18 09:51:02'
我试图获取以下2个div元素中的项目的文本内容,但得到一个错误,该元素无法找到.例如,第一个div的文本内容是"Text1".我怎么能得到那个文字?
到目前为止,我尝试过:
driver.findElement(By.xpath("//*[@id='ctrlNotesWindow']/div[3]/ul/div[1]/div[2]/div[2]")).getText())
Run Code Online (Sandbox Code Playgroud)
而且抱怨没有找到那个元素.
这是html代码:
<div class="notesData">
<div class="notesDate" data-bind="text: $.format('{0} - {1}', moment(Date).format('MMM DD, YYYY h:mm a'), User)">Text1</div>
<div class="notesText" data-bind="text: Note">Text2 on next line</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是错误,我得到:
线程"main"中的异常org.openqa.selenium.NoSuchElementException:无法定位元素:{"method":"xpath","selector":"//*[@ id ='ctrlNotesWindow']/div [3]/UL/DIV [1]/DIV [2]/DIV [2]"}
我正在测试一个相当复杂的Web应用程序.我可以获得selenium让事情到达屏幕上出现按钮的程度.
我希望selenium在出现后单击该按钮.但是使用waitForElementPresent是不够的,因为当按钮出现时,它会在一瞬间被禁用.
我需要selenium实际上等到按钮可点击之后再尝试点击它.
我甚至没有运气,试图找出IDE中是否可行.
谢谢你的帮助!
值得重新迭代,现在我只使用IDE.目前....
在我的项目中,我有一些文件类型(考虑ex*.xls),我不希望它被提交.*.xls
每次我提交这些文件时都会出现在列表中我需要一个解决方案,以便egit忽略它
如果我右键单击该文件并单击忽略它可以工作,但我在包含*.xls
文件的许多文件夹中有很大的树文件列表
我知道.gitignore
文件将忽略文件,但它应该在每个目录中,其中忽略的文件应该是非常庞大的文件夹集合,所以有一种方法可以忽略只有指定的文件类型
我在日食中使用egit
我正在Thomson Holidays网站(http://www.thomson.co.uk/holidays.html)上进行示例作业.在左侧有一个假日搜索面板.我无法识别WebDriver中的任何这些元素.但是,在IDE中,这些元素是可识别的.需要更多信息,因为这是我第一次遇到这样的问题.以下是代码示例:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.thomson.co.uk/holidays.html");
driver.findElement(By.id("searchbutton")).click();
driver.findElement(By.id("holidayAttribute_1")).click();
driver.findElement(By.id("holidayAttribute_2")).click();
driver.findElement(By.id("holidayAttribute_3")).click();
Thread.sleep(5000);
Run Code Online (Sandbox Code Playgroud) 我是Selenium的新手,只为firefox编写我的测试用例.我也想为Chrome驱动程序编写它.但是我应该在哪里下载Widows 8 64位.
selenium google-chrome webdriver selenium-chromedriver selenium-webdriver
如果我没有获得该 HTML 元素的 id 或名称或类,如何在 Selenium Python 中使用 CSS 选择器?与 XPath 相比,更喜欢 CSS 怎么样?
我试图使用Selenium/Webdriver自动将一些文本插入到使用tinymce创建的文本框中
文本框不是普通的香草文本框,因此以下不起作用:
System.out.println("Finding text input element");
WebElement element = inputWebDriver.findElement(By.xpath("//html/body/div/form/div/div/div[2]")); //not working
//WebElement element = inputWebDriver.findElement(By.tagName("form")); // not working
//WebElement element = inputWebDriver.findElement(By.id("tinymce")); // not working
System.out.println("Entering something in text input");
element.sendKeys("Test text");
Run Code Online (Sandbox Code Playgroud)
喜欢用纯文本框工作正常https://code.google.com/p/selenium/wiki/GettingStarted
下面是截图如何在浏览器的元素选项卡中看到textarea元素的位置:http: //imageshack.com/a/img812/9341/1zau.png
注意:通过selenium,我无法在'embedded'html doc中找到任何元素(我得到元素未找到错误)
我发现一个python等同于上面完成,但是,仍然希望在我的java代码中完成它:
browser.execute_script("tinyMCE.activeEditor.setContent('{}')".format(testTextVar))
Run Code Online (Sandbox Code Playgroud)