我有一個SeleniumElement代表頁面上的幾個元素,我想過濾它只包含":visible"
元素。過濾現有的SeleniumElement
我可能會改進原來的構造函數只包含一個elemnent,但我問我是否可以做一些不同的事情:給定一個特定的元素,創建一個新的元素,篩選此元素的選擇器。
事情是這樣的:
public static SeleniumElement visible(SeleniumElement element) {
// Locator.filter() doesn't really exist, the next line won't compile
By locator = element.getElementLocator().filter(":visible");
return new SeleniumElement(element.getName(), locator, element.getPage());
}
visible(myButton).click();
// Calling myButton.click() fails because there are multiple elements that match
// the selector. However, only one of them is visible right now
對不起,我是用內部包裹我們有硒並沒有注意到,其實包裝,我認爲這是硒的代碼,我不能編輯(硒有沒有SeleniumElement類!) – ripper234