小编Ani*_*udh的帖子

从Selenium Webdriver - Java中的右键菜单中选择一个选项

我正在使用Selenium webdriver.我无法从右键单击打开的选项中选择(比如说第二个)选项.

在我当前的代码中,我可以右键单击webElement但无法从右键单击后打开的列表中选择一个选项,因为它会自动消失.

Actions action= new Actions(driver);
action.contextClick(productLink).build().perform();
Run Code Online (Sandbox Code Playgroud)

因此,使用此代码,我可以右键单击,但右键菜单会自动消失.我想从右键菜单中选择说第二个选项.

请帮忙!!!

java selenium-webdriver

24
推荐指数
4
解决办法
12万
查看次数

在Java中使用HashSets时,方法retainAll的时间和空间复杂度是多少?

例如,在下面的代码中:

public int commonTwo(String[] a, String[] b)
{
    Set common = new HashSet<String>(Arrays.asList(a));
    common.retainAll(new HashSet<String>(Arrays.asList(b)));
    return common.size();
} 
Run Code Online (Sandbox Code Playgroud)

java big-o hashset

14
推荐指数
1
解决办法
7725
查看次数

使用OAuth-Signpost和Apache HttpComponents签署POST请求的正确方法是什么?

我目前正在使用OAuth-Signpost Java库来签署从客户端发送到实现OAuth身份验证的服务器的请求.在进行GET请求时(使用HttpURLConnection)一切正常:请求被签名,参数被包含,签名在目的地中匹配.但是,它似乎不适用于POST请求.我知道使用HttpURLConnection签名POST时可能出现的问题,因此我转移到Apache HttpComponents库以获取这些请求.我在以下示例中发送的参数是纯字符串和类似XML的字符串('rxml').我的代码如下:

public Response exampleMethod(String user, String sp, String ep, String rn, String rxml){

   //All these variables are proved to be correct (they work right in GET requests)
    String uri = "...";
    String consumerKey = "...";
    String consumerSecret = "...";
    String token = "...";
    String secret = "...";

  //create the parameters list
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("user", user));
    params.add(new BasicNameValuePair("sp", sp));
    params.add(new BasicNameValuePair("ep", ep));
    params.add(new BasicNameValuePair("rn", rn));
    params.add(new BasicNameValuePair("rxml", rxml));

   // create a consumer object and configure …
Run Code Online (Sandbox Code Playgroud)

java oauth http-post signpost apache-httpcomponents

12
推荐指数
1
解决办法
9197
查看次数

JSR 303 Bean验证可以与Spring Data Rest一起使用吗?

我从文档了解http://docs.spring.io/spring-data/rest/docs/2.1.2.RELEASE/reference/html/validation-chapter.html,我可以与某些前缀声明验证.

我正在使用JSR 303,因此我的域实体使用验证注释进行注释.

可以 - 如果是,如何 - 我使用JSR 303 Bean验证与Spring Data Rest?

PS:我正在使用Spring Boot

java spring-data-jpa spring-data-rest spring-boot

12
推荐指数
2
解决办法
5797
查看次数

设置内容类型放心

我正试图用放心的方式调用休息电话.我的API接受,"application/json"作为内容类型,我需要在调用中设置.我设置了如下所述的内容类型.

选项1

Response resp1 = given().log().all().header("Content-Type","application/json")
   .body(inputPayLoad).when().post(addUserUrl);
System.out.println("Status code - " +resp1.getStatusCode());
Run Code Online (Sandbox Code Playgroud)

选项2

Response resp1 = given().log().all().contentType("application/json")
   .body(inputPayLoad).when().post(addUserUrl);
Run Code Online (Sandbox Code Playgroud)

我得到的响应是"415"(表示"不支持的媒体类型").

我尝试使用普通的java代码调用相同的api,它的工作原理.出于一些神秘的原因,我不能通过RA来解决它.

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(addUserUrl);
    StringEntity input = new StringEntity(inputPayLoad);
    input.setContentType("application/json");
    post.setEntity(input);
    HttpResponse response = client.execute(post);
    System.out.println(response.getEntity().getContent());
    /*
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line = "";
    while ((line = rd.readLine()) != null) {
        System.out.println("Output -- " +line);
    }
Run Code Online (Sandbox Code Playgroud)

java rest-assured

11
推荐指数
3
解决办法
2万
查看次数

使用Selenium webdriver测试自动完成

我有一个文本框,当我输入一个字母说's'时,它会显示一个结果列表(如谷歌搜索).

我正在使用最新的selenium webdriver与java.

我试过了

sendKeys("s"),

JavascriptLibrary jsLib = new JavascriptLibrary();

jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onkeyup");

    jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onblur");

    jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onclick");

    jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onmouseup");


driver.findElement(By.id("assetTitle")).sendKeys(Keys.ENTER);
Run Code Online (Sandbox Code Playgroud)

即使在每个步骤之后添加等待之后,这些都不起作用.

有什么建议?

谢谢.

更新: -

WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com");
    WebElement query = driver.findElement(By.name("q"));
    query.sendKeys("s");
driver.findElement(By.xpath("//table[@class='gssb_m']/tbody/tr/td/div/table/tbody/tr/td/span")).click();
    driver.findElement(By.name("btnG")).click();
Run Code Online (Sandbox Code Playgroud)

更新2: -

WebDriver driver = new FirefoxDriver();
    driver.get("http://www.kayak.com/");
    WebElement query = driver.findElement(By.name("destination"));
    query.sendKeys("s");
Run Code Online (Sandbox Code Playgroud)

更新3: - 我尝试使用Selenium 1,并且通过将参数传递为'keydown'来实现fireevent方法.这应该是暂时的解决方法.

WebDriver driver = new FirefoxDriver();
    driver.get("http://www.kayak.com/");
    DefaultSelenium sel = new WebDriverBackedSelenium(driver,"http://www.kayak.com/");

    sel.type("//input[@id='destination']", "s");
    sel.fireEvent("//input[@id='destination']", "keydown");
Run Code Online (Sandbox Code Playgroud)

java selenium autocomplete webdriver

8
推荐指数
1
解决办法
2万
查看次数

一个类实现两个接口.方法属于哪个接口?

有两个接口B,C每个接口都有相同的方法public m1()

class A implements B and C 
Run Code Online (Sandbox Code Playgroud)

如果类A必须实现方法m1(),实现的方法将是哪个接口?

java interface

7
推荐指数
1
解决办法
1290
查看次数

Eclipse kepler的Java Decompiler

我已经尝试了JadClipse和JD-Eclipse插件,但是每次打开类文件时似乎都没有工作它说"找不到源".

默认情况下,我的*.class和*.class(没有源代码)都设置为'JD-Eclipse',但它似乎不起作用,还有其他人试过这个或者这两个插件现在都已弃用了吗?

以下是我的环境:

Eclipse:Kepler JDK:7

java eclipse decompiler

6
推荐指数
2
解决办法
2万
查看次数

如何在intellij IDEA中打开或调用regexTester插件

我对Intellij IDEA(社区版)插件比较陌生.

我刚安装了这个

用于在Intellij中测试和验证正则表达式的插件,但我无法从任何地方调用插件窗口.

我试着去设置>插件,但没有运气.

有人知道在intelliJ上使用这个插件吗?

java regex intellij-idea

6
推荐指数
2
解决办法
2710
查看次数

Spring Cloud Gateway 与 spring-boot-starter-web

我正在使用 Spring Cloud Gateway 为 Spring Boot 微服务创建网关。Gateway 还负责使用 Spring Security 进行 JWT 授权。

public class JwtAuthorizationFilter extends BasicAuthenticationFilter {

    ...

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        String header = request.getHeader(JwtProperties.HEADER_STRING);

        if (header == null || !header.startsWith(JwtProperties.TOKEN_PREFIX)) {
            chain.doFilter(request, response);
            return;
        }

        Authentication authentication = getUsernamePasswordAuthentication(request);
        SecurityContextHolder.getContext().setAuthentication(authentication);

        chain.doFilter(request, response);
    }

    private Authentication getUsernamePasswordAuthentication(HttpServletRequest request) {
        String token = request.getHeader(JwtProperties.HEADER_STRING).replace(JwtProperties.TOKEN_PREFIX, "");

        DecodedJWT decodedJWT = JWT.require(Algorithm.HMAC512(JwtProperties.SECRET.getBytes())).build().verify(token);
        String username = decodedJWT.getSubject();

        if (username != null) { …
Run Code Online (Sandbox Code Playgroud)

java spring-security jwt spring-boot spring-cloud-gateway

5
推荐指数
1
解决办法
9090
查看次数