我在用:
driver.manage().timeouts().implicitlyWait(180, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
但是对于下面的元素,它仍然会不断失败
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys("Create_title_01");
Run Code Online (Sandbox Code Playgroud)
我添加了等待代码:
for (int second = 0;; second++) {
if (second >= 120) fail("timeout");
try { if (isElementPresent(By.id("name"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
Run Code Online (Sandbox Code Playgroud)
不应该隐含等待,直到找到一个元素?如果我使用显式等待而不是我添加的代码,它会更好Thread.sleep()吗?
使用Selenium webdriver(Java Script)和Mocha
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
until = require('selenium-webdriver').until,
webdriver = require('selenium-webdriver');
Run Code Online (Sandbox Code Playgroud)
如果测试失败,我想使用Mocha的after函数进行屏幕截图:
function writeScreenshot(data, name) {
name = name || 'ss.png';
var screenshotPath = '/result/';
fs.writeFileSync(screenshotPath + name, data, 'base64');
};
afterEach(function () {
if (this.currentTest.state == 'failed') {
console.log("If condition");
driver.takeScreenshot().then(function (data) {
writeScreenshot(data, 'failed.png');
});
}
});
Run Code Online (Sandbox Code Playgroud)
运行测试后,如果条件返回true.但它没有创建截图.
我想在发送http请求之前设置abc = 123 cookie.
在回复中,我希望将相同的cookie发回.但是在响应中我得到abc = 890,其中值由目标服务器设置.
DefaultHttpClient httpclient = new DefaultHttpClient();
CookieStore cookieStore = httpclient.getCookieStore();
BasicClientCookie cookie = new BasicClientCookie("abc", "123");
// Prepare a request object
HttpGet httpget = new HttpGet("http://abc.net/restofurl");
cookieStore.addCookie(cookie);
httpclient.setCookieStore(cookieStore);
// Execute the request
HttpResponse response = httpclient.execute(httpget);
// Examine the response status
log.info("Http request response is: " + response.getStatusLine());
List<Cookie> cookies = cookieStore.getCookies();
for (int i=0; i<cookies.size();i++) {
if (cookies.get(i).getName().toString().equals("abc")) {
log.info("cookie is: " + cookies.get(0).getValue().toString());
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
driver.wait(until.elementIsPresent(By.css(".popup-backdrop fade")), 15000);
Run Code Online (Sandbox Code Playgroud)
我该如何做相反的事情?我想等到“.popup-backdrop fade”覆盖消失,然后再单击一个元素。
我正在使用 Selenium-webdriver(使用 Javascript 而不是使用 Java 或 Python 或 C#)
webdriver.executeScript("arguments[0].scrollIntoView();", element);
Run Code Online (Sandbox Code Playgroud)
这会将元素滚动到视图中,但它会在页面的标题后面.
如何将元素滚动到视图中,以便元素位于标题下方而不是标题后面?
我想从HTTP响应中获取cookie的域.代码是:
cookie = Cookie.SimpleCookie()
cookie.load(cookie_string)
print 'cookie = ', cookie
Run Code Online (Sandbox Code Playgroud)
这表明cookie为
cookie = Set-Cookie:Cycle = MA == | MA == | MA ==; 域= .abc.xyz.net; expires =星期二,05-Oct-2021 04:15:18 GMT; 路径= /
我想从上面的结果中提取域名.
我在尝试
print cookie['Domain']
print cookie['Domain'].value
print cookie['Cycle']['Domain'].value
Run Code Online (Sandbox Code Playgroud)
这些都不起作用.
谢谢
使用Selenium Web驱动程序而不是Selenium RC开始新的测试框架是一个好主意吗?使用Selenium Web驱动程序并非所有Selenium方法都已实现.那么使用Selenium RC是个好主意吗?
谢谢!
有没有更好的方法来同时发送数千个http GET 请求?我的代码一个接一个地发送请求。看过其他答案但无法弄清楚。谢谢。
for (int j=0; j<4; j++) {
DefaultHttpClient httpclient = new DefaultHttpClient();
CookieStore cookieStore = httpclient.getCookieStore();
HttpGet httpget = new HttpGet("");
try {
HttpResponse response = httpclient.execute(httpget);
List<Cookie> cookies = cookieStore.getCookies();
} catch (Exception e) {}
httpclient.getConnectionManager().shutdown();
}
Run Code Online (Sandbox Code Playgroud) 我试图在测试脚本中的每个web元素之前添加显式等待
我的代码有
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
.
.
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(presenceOfElementLocated(By.id("name")));
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys("Create_title_01");
Run Code Online (Sandbox Code Playgroud)
我看到的错误是:
java.lang.NullPointerException
at org.openqa.selenium.support.ui.FluentWait$1.apply(FluentWait.java:176)
at org.openqa.selenium.support.ui.FluentWait$1.apply(FluentWait.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:174)
Run Code Online (Sandbox Code Playgroud)
谢谢
我手动创建了一个 .xlsx 文件。我为某些行添加了不同的颜色,并且某些单元格具有自定义日期格式。
我正在使用 js-xlsx npm 模块从 .xlsx 文件读取数据。在写回同一个 .xlsx 文件以更新某些单元格值时,选定的颜色和日期格式将丢失。
我尝试了下面的代码,但这并没有帮助保留 .xlsx 单元格样式。
var XLSX = require('xlsx');
XLSX.readFile('abc.xlsx', {cellStyles: true});
var first_sheet_name = workbook.SheetNames[1];
var address_of_cell = 'A1';
var worksheet = workbook.Sheets[first_sheet_name];
var desired_cell = worksheet[address_of_cell];
var desired_value = desired_cell.v;
desired_cell.v = 'efg';
XLSX.writeFile('abc.xlsx', {cellStyles: true});
Run Code Online (Sandbox Code Playgroud) 字符串输入="c_Name == V-GE-DO50或c_Name == V-GE-DO-C";
我试过了
input.replaceAll(" ", "");
input.trim();
Run Code Online (Sandbox Code Playgroud)
两者都没有从字符串中删除空格
希望字符串看起来像c_Name == V-GE-DO50ORc_Name == V-GE-DO-C
谢谢
如果模式匹配或执行另一个代码块(如果模式不匹配),我将如何执行代码块?
String input = "abc";
final String mainRegex = "(.*?)(&!|&|==)";
final Matcher matcher = Pattern.compile(mainRegex).matcher(input);
Run Code Online (Sandbox Code Playgroud)
我试过了
if(matcher1.matches())
{
execute this block
}
else
{
execute this block
}
Run Code Online (Sandbox Code Playgroud)
但它总是执行else块.即使输入是a>b&!c<d.
在 Postgres DB 中,其中一列在下面发布了此 JSON 数据。
当我对该列进行“选择”查询时,我想将“lib-One-5dc422e9f21531f9dbc16fd0”和“lib-Six-5dc422e9f21531f9dbc16fd0”的 JSON 值替换为 lib-One- 和 lib-Six- 等。
我是 postgres 的新手,并且已经尝试解决这个问题有一段时间了。
基本上将任何lib-*-[0-9]值替换为lib-*-
{
"data":{
"Library":{
"Checkout":{
"invoiceId":"12dfdf454546",
"checkoutDetail":{
"invoiceTransactionId":"5ab422e9f21531f9dbc16fd6",
"invoicePaymentDetail":{
"objectId":"lib-One-5dc422e9f21531f9dbc16fd0",
"checkoutPeriods":[
{
"startDate":"2017-04-14T19:00:00.000",
"endDate":"2017-05-19T19:00:00.000"
}
],
"invoice":{
"objectId":"lib-Six-5dc422e9f21531f9dbc16fd0",
"checkObject":true
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)