现在,我在BasePage中使用以下方法,并且希望将此方法调用到其他页面上。
因此,在以下方法中,参数为(String xpathExpression)
,如何将其更改为WebElement并使用将在其他页面中定义的其他元素定位符。
protected boolean CheckSorting(String xpathExpression) {
List<WebElement> issueTypeDropdown = new LinkedList<>(driver.findElements(By.xpath(xpathExpression)));
LinkedList<String> issueTypes = new LinkedList<String>();
for (int i = 0; i < issueTypeDropdown.size(); i++) {
//System.out.println(issueTypeDropdown.get(i).getText());
issueTypes.add(issueTypeDropdown.get(i).getText());
}
return Compare(issueTypes);
}
答案 0 :(得分:2)
您无法从RequestQueue requestQueue = Volley.newRequestQueue(Result.this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray jsonArray = new JSONArray(new JSONObject().get("Data"));
for(int i = 0 ; i< jsonArray.length() ; i++) {
JSONObject object = jsonArray.getJSONObject(i);
JSONArray typearray = new JSONArray(object.get("types"));
for(int j = 0 ; j< typearray.length() ; j++)
{
JSONObject typejsion = typearray.getJSONObject(j);
type = new String[typearray.length()];
type[j] = typejsion.getString("name");
Toast.makeText(Result.this ,typejsion.getString("name"), Toast.LENGTH_LONG ).show();
}
JSONArray userarray = new JSONArray(object.get("user"));
for(int j = 0 ; j< userarray.length() ; j++)
{
JSONObject userjson = userarray.getJSONObject(j);
user = new String[typearray.length()];
user[j] = userjson.getString("name");
}
Resultinfo newresult =new Resultinfo(
user.toString(),
type.toString() ,
object.getString("date"),
object.getString("time")
);
data.add(newresult);
}
recyclerView = (RecyclerView) findViewById(R.id.list);
adapter =new ResultAdapter(data , Result.this);
recyclerView.setAdapter(adapter);
RecyclerView.LayoutManager layout = new GridLayoutManager(Result.this , 1);
recyclerView.setLayoutManager(layout);
} catch (JSONException e) {
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Volley", error.toString());
}
}
)
{
//adding parameters to the request
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("fromcountry_id", from_country);
params.put("tocountry_id",to_country);
params.put("fromcity_id", from_city);
params.put("tocity_id",to_city);
params.put("date", date);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/x-www-form-urlencoded");
return params;
}
};
requestQueue.add(stringRequest);
获取定位器。如果您希望定位器策略是动态的,则可以将WebElement
发送到方法
By
用途:
protected boolean CheckSorting(By by) {
List<WebElement> issueTypeDropdown = new LinkedList<>(driver.findElements(by));
//...
}