小编Ali*_*adi的帖子

无法在selenium webdriver中选择iframe

我试图Iframe通过类名选择一个,但它不起作用,我正在尝试它的工作,tagName但当我尝试在Iframe我不能的元素内输入时,你能帮我这里是我的代码:

webDriver driver.switchTo().frame( driver.findElement( By.className( "cke_wysiwyg_frame cke_reset" ) ) );
driver.findElement( By.xpath( "//body[contains(text(),'type here')]" ) ).sendKeys( "Testing" );
Run Code Online (Sandbox Code Playgroud)

这是我网页上的HTML:

<div id="cke_534_contents" class="cke_contents cke_reset" role="presentation" style="height: 75px;">
   <span id="cke_586" class="cke_voice_label">Press ALT 0 for help</span>
   <iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" aria-describedby="cke_586" tabindex="0" allowtransparency="true">
      <!DOCTYPE html>
      <html lang="en-gb" dir="ltr">
         <head>
         <body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="true">
            type here
         </body>
      </html>
   </iframe>
</div>
Run Code Online (Sandbox Code Playgroud)

java iframe selenium selenium-webdriver

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

错误:包 org.testng.annotations 不存在 [javac] import org.testng.annotations.Test;

我有一个简单的项目,我正在尝试使用 Ant 构建它。我的项目包含 testng,但是当我尝试运行构建时收到一条错误消息。请你帮助我好吗?我花了很多时间试图找出问题所在,但到目前为止还没有任何结果。

这是项目:

package selenium;

import org.testng.annotations.Test;

public class HomePage {

    @Test
    public void test(){

        System.out.println("this is test");
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我有一个包含 testng.jar 的 lib 文件,我有一个运行该类的 test.xml 套件,这是我的构建文件:

package selenium;

import org.testng.annotations.Test;

public class HomePage {

    @Test
    public void test(){

        System.out.println("this is test");
    }
}
Run Code Online (Sandbox Code Playgroud)

java ant testng

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

如何使用testng并行运行我的硒测试方法

我正在尝试使用testng并行运行我的自动化测试(Selenium webdriver).这是我正在运行的节点:

java -Dwebdriver.gecko.driver=chromedriver.exe -jar selenium-server-standalone-3.4.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=chrome,maxInstances=2 -maxSession 2
Run Code Online (Sandbox Code Playgroud)

这是我的测试类:

public class TestParallel {

Login login;

//@BeforeMethod(alwaysRun = true)
public SeleniumDriverCore testSetup() throws FileNotFoundException, IOException{
    SeleniumDriverCore driver = new SeleniumDriverCore("config/chromeDriverConfig");
    Properties config = new Properties();
    config.load(new FileInputStream("config/testConfig"));
    this.login = new Login(driver);
    driver.browser.open("https://test.test.xyz");

    driver.browser.maximize();
    driver.waits.waitForPageToLoad();
    return driver;
}

@Test(groups={"parallel"})
public void test_one() throws FileNotFoundException, IOException{
    SeleniumDriverCore driver=testSetup();
    login.navigateToPage(Pages.LOGIN);
    login.assertion.verifyLoginPopupAndTitleDisplayed();
    testCleanup(driver);
}

@Test(groups={"parallel"})
public void test_two() throws FileNotFoundException, IOException{
    SeleniumDriverCore driver=testSetup();
    login.navigateToPage(Pages.LOGIN);
    login.assertion.verifyLoginPopupAndTitleDisplayed();
    testCleanup(driver);
}

@Test(groups={"parallel"})
public …
Run Code Online (Sandbox Code Playgroud)

java testng selenium selenium-grid parallel-testing

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

如何使我的方法使用 Wait.Until 忽略 selenium webdriver 中的抛出异常

我有一个方法是

private boolean findElements(
                                  String xpath,
                                  int timeOut ) {

        WebDriverWait wait = new WebDriverWait( driver, timeOut );

        try {
            if( wait.until( ExpectedConditions.visibilityOfElementLocated( By.xpath( xpath ) ) ) != null ) {
                return true;
            } else {
                return false;
            }
        } catch( NoSuchElementException e ) {
            e.printStackTrace();
            return false;
        }

    }
Run Code Online (Sandbox Code Playgroud)

它在找到元素时返回 true,但在未找到元素时抛出异常,我如何使方法返回 false 而不是抛出异常,或者是否有更好的布尔值方法或方法可以为我完成这项工作.

亲切的问候

java selenium-webdriver

0
推荐指数
1
解决办法
7630
查看次数