小编Gra*_*ell的帖子

如何控制Chromedriver打开窗口尺寸?

我正在使用Selenium WebDriver进行自动化,而我正在使用Chromedriver.

我注意到当我的驱动程序运行并打开Chrome浏览器时,它会打开一个奇怪的大小的浏览器.我试图修复但是徒劳无功.

有谁知道我怎么改变它?

selenium selenium-chromedriver

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

如何使用spock框架进行参数捕获?

我有一些像这样的Java东西:

public interface EventBus{
    void fireEvent(GwtEvent<?> event);
}


public class SaveCommentEvent extends GwtEvent<?>{
    private finalComment oldComment;
    private final Comment newComment;

    public SaveCommentEvent(Comment oldComment,Comment newComment){
        this.oldComment=oldComment;
        this.newComment=newComment;
    }

    public Comment getOldComment(){...}
    public Comment getNewComment(){...}
}
Run Code Online (Sandbox Code Playgroud)

并测试代码如下:

  def "...."(){
     EventBus eventBus=Mock()
     Comment oldComment=Mock()
     Comment newCommnet=Mock()

     when:
         eventBus.fireEvent(new SaveCommentEvent(oldComment,newComment))

     then:
         1*eventBus.fireEvent(
                                {
                                   it.source.getClass()==SaveCommentEvent;
                                   it.oldComment==oldComment;
                                   it.newComment==newComment
                                 }
                              )            
}
Run Code Online (Sandbox Code Playgroud)

我想验证eventBus.fireEvent(..)获取与类型的事件称为一次SaveCommentEvent和施工参数oldCommentnewComment.

代码运行没有错误,但问题是:

更改封闭后的东西

{
   it.source.getClass()==SaveCommentEvent;
   it.oldComment==oldComment;  //old==old
   it.newComment==newComment   //new==new
}
Run Code Online (Sandbox Code Playgroud)

 {
    it.source.getClass()==Other_Class_Literal;
    it.oldComment==newComment;  //old==new
    it.newComment==oldComment   //new==old …
Run Code Online (Sandbox Code Playgroud)

spock

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

Selenium Javascript执行器返回null

null通过Selenium运行时返回以下JavaScript代码JavascriptExecutor.但是,在Firefox开发人员控制台中运行时,相同的代码返回了一个值.

function tmp(){
    var attrb = jQuery(jQuery("[name='q']")[0]).attr('type');
    if(typeof attrb !== 'undefined' && attrb !== false){
        return attrb;
    } else {
        return '';
    }
}

tmp();
Run Code Online (Sandbox Code Playgroud)

以下是我的WebDriver代码,JS与上面相同:

JavascriptExecutor jsExec = (JavascriptExecutor)driver;
Object inpType = 
       jsExec.executeScript("function tmp(){...}tmp();");
System.out.println("Type: " + inpType);
Run Code Online (Sandbox Code Playgroud)

以上输出null而不是"文本"字符串.有任何想法吗?

javascript selenium nullpointerexception selenium-webdriver

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

wait.until(ExpectedConditions.visibilityOf Element1 OR Element2)

我希望使用wait.until(ExpectedConditions)两个元素.我正在运行测试,我需要WebDriver等到Element1或Element2中的任何一个出现.然后我需要选择先出现的人.我试过了:

WebDriverWait wait = new WebDriverWait(driver, 60); 
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@class='....']"))) || wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h3[@class='... ']"))); 

        // Then I would need:

String result = driver.findElement(By.xpath("...")).getText() || driver.findElement(By.xpath("...")).getText();
Run Code Online (Sandbox Code Playgroud)

总而言之,我需要等到两个元素中的任何一个出现.然后挑选出现的人(他们不能同时出现)请帮助.

java selenium

8
推荐指数
3
解决办法
5万
查看次数

流利的等待和WebDriver等待 - 差异

我已经看到了使用Selenium的代码FluentWaitWebDriverWait代码.FluentWait使用轮询技术,即它将针对特定的每个固定间隔进行轮询WebElement.我想知道该怎么WebDriverWaitExpectedConditions

考虑以下Java示例:

WebDriverWait wait = new WebDriverWait(driver, 18);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Account")));

WebElement element = driver.findElement(By.linkText("Account"));
element.sendKeys(Keys.CONTROL);
element.click();
Run Code Online (Sandbox Code Playgroud)

ExpectedConditions.elementToBeClickable(By.linkText("Account"))监视器是否linkText("Account")可点击或在点击之前等待18秒?

selenium selenium-webdriver

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

for ... in循环不循环遍历所有属性?

当我加载页面时,会创建一个nodeList,它看起来像这样:

[text, h4, text, span, br, input, br, span, br, input, br, span, br, input, br, span, br, input, br]
Run Code Online (Sandbox Code Playgroud)

我创建了一个for循环遍历所有这些元素的简单循环,并从DOM中删除它们中的每一个.(所有元素都在a <section>)

这是循环:

        for(element in videoTitlesElement.childNodes){
            if(!isNaN(element)){
                videoTitlesElement.removeChild(
                        videoTitlesElement.childNodes[element]);
            }
        }
Run Code Online (Sandbox Code Playgroud)

但是,在循环结束时,nodeList如下所示:

[h4, span, input, span, input, span, input, span, input]
Run Code Online (Sandbox Code Playgroud)

并非所有元素都被删除.为什么?

谢谢.

javascript for-loop nodelist for-in-loop

4
推荐指数
1
解决办法
155
查看次数