xpath是 //div[contains(@class, 'a b') and not (contains(@style, 'c'))]
等效的CSS选择器是什么?容易得到第一位div[class*='a b']
,但如何否定和结合它们?
我已经对此做了一些阅读,但未能找到具体的东西.我有一个需要与Selenium交互的画布对象.但是我们都知道画布对象就像一个封闭的盒子.我读到你可以在JS代码中添加'hooks'来绘制画布,以允许Selenium捕获这些钩子并使用某些东西.
但我不确定我怎么能这样做.有没有人愿意分享任何经验或小例子?
这是我的HTML代码
<div class="selectCard_left">
<input id="26110162" class="default_shipping_address" type="radio" name="address" checked="true">
<span>Seleccionar como tarjeta predeterminada</span>
Run Code Online (Sandbox Code Playgroud)
我正在努力driver.findElement(By.id("17390233")).isSelected();
,但我没有任何价值.
我们在Apache配置中有一堆重定向.我想用Selenium自动测试重定向,这导致了一些问题:
也许Selenium不是最好的解决方案.还有其他建议吗?
在keypress
运行事件侦听器的网页上,我希望能够测试发送击键.但该页面没有输入元素和调用
driver.FindElement(By.XPath("//body")).SendKeys("abc");
Run Code Online (Sandbox Code Playgroud)
引发关于需要元素可编辑以接受击键的错误(针对Chrome).
有没有办法生成击键,以便页面看到它们而不注入虚拟输入元素?
使用IE进行自动化使用Selenium Webdriver时,我可以打开URL,但在该页面上找到该元素会引发以下异常:
org.openqa.selenium.NoSuchWindowException:无法在关闭的窗口中找到元素(警告:服务器未提供任何堆栈跟踪信息)
我尝试过这种driver.switchTo.window()
方法,但它没有用.我已经搜索了几个小时,我没有到达任何地方.
这是代码:
public static Selenium selenium;
public static void main(String args[]) {
try {
System.setProperty(
"webdriver.ie.driver",
"D:\\Driver\\IEDriverServer_Win32_2.32.3_latest\\IEDriverServer.exe");
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
WebDriver driver = new InternetExplorerDriver(capab);
driver.get("http://www.google.com");
driver.findElement(By.xpath(".//*[@id='addlang']/a[1]")).click();
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) java selenium internet-explorer exception selenium-webdriver
我正在练习使用cssGetValue方法从特定Web元素的CSS属性中检索值.
我有两个问题:
为什么cssGetValue方法返回值13px,哪个web元素执行实际引用的方法.1A.我想获得标记为"By ID"的部分的CSS属性.我应该如何修改我的代码,以便我可以获得id ="by-id"部分的CSS属性值?
我使用了driver.close()方法,但是在脚本完成后它不会关闭浏览器.请解释为什么在这种情况下driver.close()方法不起作用.
这是我的代码片段:
package wd_findElementBy;
import java.util.List;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SearchWebElements
{
WebDriver driver = new FirefoxDriver();
private String baseUrl= "http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example";
@Test
public void findElements(){
driver.get(baseUrl);
try{
List<WebElement> elements = driver.findElements(By.id("by-id"));
System.out.println("number of elements: " + elements.size());
for(WebElement ele : elements){
System.out.println(ele.getTagName());
System.out.println("get the text for web element with id='by-id' ");
System.out.println("------------------------------------------------------------");
System.out.println(ele.getText());
System.out.println("------------------------------------------------------------");
System.out.println(ele.getAttribute("id"));
System.out.println(ele.getCssValue("font-size"));
}
}
finally{
//driver.close();
driver.quit();
}
} …
Run Code Online (Sandbox Code Playgroud)我在Eclipse中使用Selenium WebDriver,我正在尝试将文本插入到网页上的tinymce框中.这是我正在使用的代码.
//find tinymce iframe
editorFrame = driver.findElement(By.cssSelector(".col_right iframe"));
//switch to iframe
driver.switchTo().frame(editorFrame);
driver.findElement(By.className("mceContentBody")).sendKeys("YOOOO");
driver.switchTo().defaultContent();
Run Code Online (Sandbox Code Playgroud)
光标在编辑器内闪烁,但不发送任何文本.我也尝试过这种轻微的变化而没有任何运气.
//find tinymce iframe
editorFrame = driver.findElement(By.cssSelector(".col_right iframe"));
//switch to iframe
driver.switchTo().frame(editorFrame);
WebElement body = driver.findElement(By.className("mceContentBody"));
body.sendKeys("YOOOO");
driver.switchTo().defaultContent();
Run Code Online (Sandbox Code Playgroud) 运行 selenium IDE 脚本以自动填写表单时,我收到以下信息:
[error] There was an unexpected Alert! [Javascript Error :MY-SUPER-TOP-SECRET-URL line 37 Error: NS_ERROR_XPC_SECURITY_MANAGER_VETO: ]
Run Code Online (Sandbox Code Playgroud)
当我检查第 37 行时,它是一个设置全局 bool 的小代码块,包含在一个 jQuery click() anon 函数中。
parent.jQuery(parent.document).click(function () {
parent.sharedVars.enableGenderKey = false;
});
Run Code Online (Sandbox Code Playgroud)
我正在运行 jQuery 1.8.3。有小费吗?有趣的是,表单确实成功填写了一次,但在尝试 2 及以上时,它出错了。
我有测试确保时间戳不会改变。他们在我的本地环境中通过,但在构建中失败。它与“updated_at”返回的值有关,即将第二个小数的最后 3 位数字更改为 0。以下是失败的示例:
RSpec::Expectations::ExpectationNotMetError:
expected: 2015-01-06 10:16:29.948655841 -0500
got: 2015-01-06 10:16:29.948655000 -0500
RSpec::Expectations::ExpectationNotMetError:
expected: 2015-01-06 10:16:31.236196108 -0500
got: 2015-01-06 10:16:31.236196000 -0500
Run Code Online (Sandbox Code Playgroud)
如何构建断言以忽略最后 3 位数字?是否有一个时间函数只比较时间,比如分数的百位?
谢谢。