ui4j帮助列表中的标签

时间:2015-10-07 15:35:38

标签: java ui4j

我需要从这个webpage获取一些数据。我需要点击选项卡,但我不能把它们作为元素 FF检查员的代码是:

    let view1: UIView!
    let view2: UIView!
    let sharedSuperView = view1.getSharedSuperview(withOtherView: view2)

/**
* A set of helpful methods to find shared superview for two given views
*
* @author Alexander Volkov
* @version 1.0
*/
extension UIView {

    /**
    Get nearest shared superview for given and otherView

    - parameter otherView: the other view
    */
    func getSharedSuperview(withOtherView otherView: UIView) {
        (self.getViewHierarchy() as NSArray).firstObjectCommonWithArray(otherView.getViewHierarchy())
    }

    /**
    Get array of views in given view hierarchy

    - parameter view:        the view whose hierarchy need to get
    - parameter accumulator: the array to accumulate views in

    - returns: the list of views from given up to the top most view
    */
    class func getHierarchyForView(view: UIView?, var accumulator: [UIView]) -> [UIView] {
        if let superview = view?.superview {
            accumulator.append(view!)
            return UIView.getHierarchyForView(superview, accumulator: accumulator)
        }
        return accumulator
    }

    /**
    Get array of views in the hierarchy of the current view

    - returns: the list of views from cuurent up to the top most view
    */
    func getViewHierarchy() -> [UIView] {
        return UIView.getHierarchyForView(self, accumulator: [])
    }

}

我已经尝试了我能想到的一切,但似乎没有任何效果。我唯一得到的就是阅读标签 <div id="dnn_ctr521_View_RadTabStrip2" class="RadTabStrip RadTabStrip_Outlook RadTabStripTop_Outlook pageTabs"> <div class="rtsLevel rtsLevel1"> <ul class="rtsUL"> <li class="rtsLI rtsFirst"> <a class="rtsLink rtsSelected" href="#"> <span class="rtsOut"> <span class="rtsIn"> <span class="rtsTxt"> Επισκόπηση </span> </span> </span> </a> </li> <li class="rtsLI"> <a class="rtsLink rtsAfter" href="#"> <span class="rtsOut"> <span class="rtsIn"> <span class="rtsTxt"> Υποέργα </span> </span> </span> </a> </li> <li class="rtsLI"></li> <li class="rtsLI"></li> <li class="rtsLI rtsLast"></li> </ul> </div> 这给了我这个:

document.query("#dnn_ctr521_View_RadTabStrip2")

但我不能继续

1 个答案:

答案 0 :(得分:0)

不需要单击标签页来提取数据。标签已经加载了初始数据。

package com.ui4j.sample;

import com.ui4j.api.browser.BrowserEngine;
import com.ui4j.api.browser.BrowserFactory;
import com.ui4j.api.browser.Page;
import com.ui4j.api.dom.Document;
import com.ui4j.api.dom.Element;

public class Main {

    public static void main(String[] args) {
        BrowserEngine engine = BrowserFactory.getWebKit();
        Page page = engine.navigate("http://anaptyxi.gov.gr/ergopopup.aspx?mis=277649");

        page.show();

        Document document = page.getDocument();

        // click to second tab
        document.queryAll(".rtsLI").get(1).click();

        // extract content from the first tab
        Element firstTab = document.query("#dnn_ctr521_View_pageEpiskopisi").get();
        String value = firstTab.query(".stoixeiaValues").get().getText().get();
        System.out.println(value); // prints 22.146.837 €

        // #dnn_ctr521_View_pageIpoerga second tab
        // #dnn_ctr521_View_pagePoreia third tab
        // #dnn_ctr521_View_pageForeis fourth tab
        // #dnn_ctr521_View_pageEggrafa fifth tab
    }
}