0
public void Test003() {
    new Select (webDriver.findElement(By.cssSelector("select"))).selectByVisibleText("NEC_COCONA_GG3");

    webDriver.manage().timeouts().implicitlyWait(1,TimeUnit.MILLISECONDS); 
    webDriver.findElement(By.xpath("//div[@id='main-menu']/ul/li[5]/a")).click();
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
    webDriver.findElement(By.id("issue_subject")).sendKeys("Test");
    webDriver.findElement(By.id("issue_description")).sendKeys("Test");
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
    new Select(webDriver.findElement(By.id("issue_assigned_to_id"))).selectByVisibleText("<<me>>");
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
    new Select(webDriver.findElement(By.id("issue_custom_field_values_7"))).selectByVisibleText("QA");
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
    webDriver.findElement(By.id("issue_custom_field_values_27")).sendKeys("Test");
    webDriver.findElement(By.xpath("//*[@id='attachments_fields']/span/input[1]")).sendKeys("D:\\NEC new\\log\\EASCrash.txt");
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
    webDriver.findElement(By.xpath("//*[@id='attachments_form']/span[2]/a")).click();
    webDriver.findElement(By.xpath("//*[@id='attachments_fields']/span[2]/input[1]")).sendKeys("D:\\NEC new\\log\\crash_info_201304171712.txt");
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
    webDriver.findElement(By.xpath("//input[@name='issue[watcher_user_ids][]' and @value='102']")).click();
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
    webDriver.findElement(By.xpath("//*[@id='issue-form']/input[1]")).click();
    webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.MILLISECONDS); 
}

运行脚本 selenium 时无法获取

new Select (webDriver.findElement(By.cssSelector("select"))).selectByVisibleText("NEC_COCONA_GG3");

选择失败的测试用例。

显示的错误是:

org.openqa.selenium.WebDriverException: Driver does not support finding an element by selector: select
4

2 回答 2

0

我认为您的问题可能源于多项选择。是否有任何属性可以唯一标识选择框?如果是这样,那么您需要唯一标识它。如果上面有名字,那么做

By.cssSelector("select[name='someName']");

一个标题甚至可以工作。

By.cssSelector("select[title^='Select your']");

如果你有一个开放的心态,试试这个框架。(你可以在这里下载。

您的测试将被重构为:

@Config(url="http://systemunder.test", browser=Browsers.CHROME)
public class MyTest extends AutomationTest {
    @Test
    public void Test003() {
        selectOptionByText (By.cssSelector("select"))
        .click             (By.cssSelector("div#main-menu > ul > li:nth-child(5) > a"))
        .setText           (By.id("issue_subject"), "Test")
        .setText           (By.id("issue_description"), "Test")
        .selectOptionByText(By.id("issue_assigned_to_id"), "<<me>>")
        .selectOptionByText(By.id("issue_custom_field_values_7"), "QA")
        .setText           (By.id("issue_custom_field_values_27"), "Test")
        .setText           (By.cssSelector("*#attachments_fields > span > input:nth-child(1)"), "D:\\NEC new\\log\\EASCrash.txt")
        .click             (By.cssSelector("*#attachments_form > span:nth-child(2) > a"))
        .setText           (By.cssSelector("*#attachments_fields > span:nth-child(2) > input"), "D:\\NEC new\\log\\crash_info_201304171712.txt")
        .click             (By.cssSelector("input[name='issue[watcher_user_ids][]'][value='102]"))
        .click             (By.cssSelector("form#issue-form > input:nth-child(1)"));
    }
}

您不必担心像那样的隐式等待......这一切都由框架处理。

于 2013-10-18T14:02:55.333 回答
-1

试试这个:

webDriver.findElement(By.xpath("//select"))

似乎 CSS 选择器存在问题,但使用 XPath 应该可以。

于 2013-10-18T12:49:16.940 回答