第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Selenium:將 WebElements 添加到列表中,然后檢查所有這些元素的可見(jiàn)性

Selenium:將 WebElements 添加到列表中,然后檢查所有這些元素的可見(jiàn)性

人到中年有點(diǎn)甜 2021-05-31 17:01:27
使用 Selenium 和 Cucumber,我嘗試設(shè)置一種方法來(lái)通過(guò) args 存儲(chǔ) WebElements。然后使用第二種方法,我試圖檢查列表中所有元素的可見(jiàn)性。我有一些元素是這樣定位的: @FindBy(how = How.XPATH, using = "//*  [@id=\"content\"]/section/fieldset/form/div[1]/div[2]/input") public WebElement formName; @FindBy(how = How.CSS, using = "//*  [@id=\"content\"]/section/fieldset/form/div[2]/div[2]/input") public WebElement formPassword; @FindBy(how = How.ID, using = "remember") public WebElement rememberMe; @FindBy(how = How.CLASS_NAME, using = "button principal") public WebElement loginButton;然后我寫了這個(gè)方法來(lái)在列表中添加 WebElements:public void crearListaWebElement(WebElement... elements){    List<WebElement> webElementList = new ArrayList<>();    for (WebElement element : elements){        webElementList.add(elements);    }}在 .add(elements) 1o 問(wèn)題上出現(xiàn)此錯(cuò)誤:添加 (java.util.Collection) in List 不能應(yīng)用于 (org.openqa.selenium.WebElement[])無(wú)法弄清楚為什么我不能將這些相同類型的元素添加到我的列表中然后,這是檢查可見(jiàn)性的第二種方法:public void estaVisible(WebDriver(tried WebElement as well) visibleWebElements) {    boolean esvisible =  driver.findElement(visibleWebElements).isDisplayed();    Assert.assertTrue(esvisible);    return esvisible;}在“visibleWebElement”上收到此錯(cuò)誤:WebDriver 中的 findElement (org.openqa.selenium.By) 不能應(yīng)用于 (org.openqa.selenium.WebDriver)我了解 2 種不同類型的對(duì)象之間的沖突,但是,WebDriver 找到的對(duì)象不是存儲(chǔ)為 WebElements 的嗎?有人可以在這里放一些燈嗎?提前致謝。  
查看完整描述

3 回答

?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

無(wú)法弄清楚為什么我不能將這些相同類型的元素添加到我的列表中 -


您的代碼中很可能有拼寫錯(cuò)誤。它應(yīng)該是element而不是elements:


for (WebElement element : elements){

        webElementList.add(element);

    }

在“visibleWebElement”上出現(xiàn)此錯(cuò)誤 -


driver.findElement()方法接受一個(gè)By對(duì)象作為參數(shù),它是一個(gè)選擇器。但是您正在傳遞visibleWebElementswhich 是一個(gè)WebElement對(duì)象,這就是您的代碼出錯(cuò)的原因。例如,如果您想通過(guò) xpath 定位元素,這是使用它的正確方法:


WebElement your_element = driver.findElement(By.xpath("//whatever xpath"));

您可以直接isDisplayed()在 WebElement 上使用該方法:


public void estaVisible(WebElement visibleWebElements) {


    boolean esvisible =  visibleWebElements.isDisplayed();

    Assert.assertTrue(esvisible);

    return esvisible;

}


查看完整回答
反對(duì) 回復(fù) 2021-06-02
?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

此函數(shù)將返回一個(gè)布爾值并檢查列表元素是否可見(jiàn)。


public boolean isListElementsVisible(WebDriver driver, By locator) {

    boolean result = false;

    try {

        WebDriverWait wait = new WebDriverWait(driver, 30);

        wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(locator));

        result = true;

    } catch (Exception e) {

        System.out.println(e.getMessage());

        result = false;

    }

   return result;

}


查看完整回答
反對(duì) 回復(fù) 2021-06-02
  • 3 回答
  • 0 關(guān)注
  • 473 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)