Selenium,单击一个按钮并循环迭代循环失败

时间:2017-03-02 12:21:10

标签: selenium iterator click

我有一个测试

public class SeleniumForh extends BaseTest {

    private static List<String> FNR;
    private static final int THREAD_COUNT = 1;

    private static Set<String> THREADS = Collections.synchronizedSet(new HashSet<String>());

    static {
        List<String> fnr = new ArrayList<String>();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(SeleniumManntallskryss.class.getResourceAsStream("/fnr")));
            String line;
            while ((line = reader.readLine()) != null) {
                fnr.add(line);
            }
            FNR = Collections.synchronizedList(fnr);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public SeleniumForhandstemmer(String platform, String browserName, String browserVersion) {
        super(platform, browserName, browserVersion);
}

    @Parameterized.Parameters
    public static LinkedList<String[]> getEnvironments() throws Exception {
        LinkedList<String[]> env = new LinkedList<String[]>();


        for (int i = 0; i <THREAD_COUNT; i++) {
            env.add(new String[]{"ANY", "firefox", "35"});
        }
        return env;
    }

    @Test
    public void testForhand() throws Exception {
        try {
            System.out.println(System.currentTimeMillis() + " - " + Thread.currentThread() + ": testForhand");

            THREADS.add(Thread.currentThread().toString());
            do {
                System.out.println(System.currentTimeMillis() + " - " + Thread.currentThread() + ": THREADS.size() = " + THREADS.size());
                Thread.sleep(5000);
            } while (THREADS.size() < THREAD_COUNT);

            System.out.println(System.currentTimeMillis() + " - " + Thread.currentThread() + ": testForhand - ready to run");

            WebDriver driver = webDriverThreadLocal.get();
            driver.get("https://kill");

            Assert.assertTrue(driver.getTitle().equals("Ehh"));
            WebElement element = driver.findElement(By.xpath("/html/body/div/div[3]/div/div[2]/div/div/div/a"));
            element.click();

            WebElement brukerid = driver.findElement(By.xpath("/html/body/form/input[1]"));
            brukerid.clear();
            brukerid.sendKeys(new CharSequence[]{"2333"});
            WebElement logginnknapp = driver.findElement(By.cssSelector("input[value=\"Login\"]"));
            logginnknapp.click();

            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

            WebElement rolle = driver.findElement(By.cssSelector("#event33"));
            rolle.click();

            for (int i = 0; i < 10; i++) {

                System.out.println("Re nr " + (i + 1));

                WebElement fo = driver.findElement(By.linkText("Ree"));
                fo.click();

                WebElement sted = driver.findElement(By.xpath("//*[@id=\"form:panel:tabell_dd_data\"]/tr[1]/td"));
                sted.click();

                takeScreenshot("nod");

                WebElement velg = driver.findElement(By.xpath("//*[@id=\"form:panel:tabeller\"]/div/div[2]"));
                velg.click();

                WebElement fnrFane = driver.findElement(By.xpath("//*[@id=\"mand:manntallsSokForm:tabView\"]/ul/li[2]"));
                fnrFane.click();

                WebElement velger = driver.findElement(By.xpath("//input[@data-aft=\"fodselsnummer\"]"));
                velger.clear();
                String fnr = FNR.remove(0);
                velger.sendKeys(fnr);
                WebElement sokknapp = driver.findElement(By.xpath("//*[@id=\"mad:tabView:searchSSN\"]"));
                sokknapp.click();

                Thread.sleep(10000);

                WebElement fnrTxt = driver.findElement(By.xpath("//*[contains(text(), '" + fnr + "')]"));
                System.out.println("Fnr tekstelement: " + fnrTxt);

                WebElement regStemme = driver.findElement(By.xpath("//*[@id=\"stemmegivning:form:markOffAdvance\"]"));
                System.out.println("Knd: " + regStemme);
                regStemme.click();

                driver.findElement(By.xpath("//*[contains(text(), 'bd')]"));

                driver.get("https://y");

                driver.findElement(By.xpath("//*[contains(text(), 'Min side')]"));
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            System.out.println(System.currentTimeMillis() + " - " + Thread.currentThread() + ": testSimple - test finished");
        }
    }
}

问题是当运行secound iteratoion时,我要点击的按钮只是在正在运行的浏览器中用方框标记,而不是cliked。这种情况发生在第二次(不是第一次迭代),我尝试在迭代之间休眠,并且还确认按钮我发现,所以问题是点击功能。而且我可以看到它试图点击,因为正方形在buttoon周围出现。

0 个答案:

没有答案