我处理的一些网站有很多ajax请求.我打算在点击断言元素之前等待Ajax请求完成.目前我用
try {
if (driver instanceof JavascriptExecutor) {
JavascriptExecutor jsDriver = (JavascriptExecutor)driver;
for (int i = 0; i< timeoutInSeconds; i++)
{
Object numberOfAjaxConnections = jsDriver.executeScript("return jQuery.active");
// return should be a number
if (numberOfAjaxConnections instanceof Long) {
Long n = (Long)numberOfAjaxConnections;
System.out.println("Number of active jquery ajax calls: " + n);
if (n.longValue() == 0L) break;
}
Thread.sleep(1000);
}
}
else {
System.out.println("Web driver: " + driver + " cannot execute javascript");
}
}
catch (InterruptedException e) {
System.out.println(e);
}
Run Code Online (Sandbox Code Playgroud)
但它适用于Ajax请求,但不适用于任何具有jQuery库变体的类似请求. …
我使用sf.json库来映射我的Web应用程序中的传入请求的表单数据.
让我们说传入的请求是http:// localhost:8080/app/addProfile,表单数据为:
formData: {
"name":"applicant Name",
"Age":"26",
"academics":{
"college":"80",
"inter":"67",
"matriculation":"89"
},
"skill":{
"computer":"c,c++,java",
"maths":"limit,permutation,statistics"
},
"dateOfBirth":"09-07-1988"
}
Run Code Online (Sandbox Code Playgroud)
服务器端 :
String requestFormData=request.getParameter("formData");
JSONObject formData = JSONObject.fromObject(requestFormData);
String name= formData.getString("name");
if(name.length>70){
//error message for length validation
}
if(!name.matches("regex for name"){
//error message for name validation
}
...
...
...
Run Code Online (Sandbox Code Playgroud)
这种方法的主要问题是如果结构中有微小的修改JSON,那么整个代码需要修改.
是否有任何API可以配置验证所需的规则?
我尝试了很多方案来制作一个脚本,该脚本将无法成功提高音量。这里的例子:
tell application "System Events"
set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
tell application "Spotify"
set volcheck to get sound volume
set volcheck to (volcheck + 10)
set sound volume to volcheck
end tell
end if
Run Code Online (Sandbox Code Playgroud)
要么 :
tell application "System Events"
set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
tell application "Spotify"
set sound volume to (sound volume + 10)
end tell …Run Code Online (Sandbox Code Playgroud) java ×2
ajax ×1
applescript ×1
jquery ×1
json ×1
rules ×1
selenium ×1
spotify ×1
spotify-app ×1
validation ×1
webdriver ×1