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

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

如何使用 selenium 網(wǎng)絡(luò)驅(qū)動(dòng)程序選擇復(fù)選框

如何使用 selenium 網(wǎng)絡(luò)驅(qū)動(dòng)程序選擇復(fù)選框

有只小跳蛙 2023-06-08 17:37:08
在我的網(wǎng)頁(或彈出窗口)中,有多個(gè)輸入框和復(fù)選框。輸入框和復(fù)選框位于單獨(dú)的 div 標(biāo)簽中。這是我的 html 代碼:<div class="modal-body-large">    <div class="col-md-12 step-forms custom-tab-content">        <form class="form-horizontal form-sections">            <div class="form-group">                <label class="control-label col-sm-2">Username<span class="red">*</span></label>                <div class="col-sm-10">                    <input name="userId" class="form-control custom-form-control" type="text" placeholder="Username" value="">                </div>            </div>            <div class="form-group">                <label class="control-label col-sm-2">Email<span class="red">*</span></label>                <div class="col-sm-10">                    <input name="email" class="form-control custom-form-control" type="text" placeholder="Email" value="">                </div>            </div>            .....        </form>    </div>    <div class="col-md-12 step-forms custom-tab-content">        <form class="form-horizontal"><span class="help-block" style="font-size: small;"><i>Note: Optional</i></span>            <div class="col-md-6">                <div>                    <div class="form-sections">                        <ul>                            <li>Select permissions</li>                            <li>                                <input type="checkbox" id="permissions1565851434728" name="permissions">                                <label for="permissions1565851434728" class="xh-highlight">Select all</label>                            </li>                        </ul>                        <div class="searchbox-container">                            <div class="check-list">                                <ul>當(dāng)我來到這個(gè)頁面時(shí),我能夠成功地在輸入字段中輸入文本。當(dāng)涉及到選擇復(fù)選框時(shí),我必須為該復(fù)選框提供完整的 xpath。就像,如果我想選擇復(fù)選框全選,我將 xpath 指定為我擔(dān)心有沒有其他方法可以做到這一點(diǎn)?
查看完整描述

4 回答

?
哈士奇WWW

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

要在與as?Select all關(guān)聯(lián)的復(fù)選框click()上,因?yàn)樗璧脑卦?em>Modal Dialog中,您必須為此引入WebDriverWait并且您可以使用以下Locator Strategy:<label>elementToBeClickable()

  • xpath:

    new?WebDriverWait(driver,?20).until(ExpectedConditions.elementToBeClickable(By.xpath("http://li[text()='Select?permissions']//following::li[1]//label"))).click();



查看完整回答
反對(duì) 回復(fù) 2023-06-08
?
汪汪一只貓

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

選擇復(fù)選框類似于單擊按鈕。我看到有id所有復(fù)選框和value一些復(fù)選框的字段。所以你可以使用下面的方法來完成你所需要的。


id通過將復(fù)選框傳遞給 來選擇復(fù)選框XPath,


driver.findElement(By.xpath(".//*[@id='permissions1565851434728']")).sendKeys(Keys.SPACE);

您可以單擊復(fù)選框而不是像下面這樣發(fā)送密鑰,


WebElement checkBox = driver.findElement(By.id("permissions1565851434728"));

checkBox.click();

value通過將復(fù)選框傳遞給 來選擇復(fù)選框CSSSelector,


WebElement checkBox = driver.findElement(By.cssSelector("input[value='Add/Update Network Security']"));

checkBox.click();

如果有 2 個(gè)復(fù)選框,您可以按如下方式使用,


driver.FindElements(By.xpath("(//input[@type='checkbox'])[1]"));

driver.FindElements(By.xpath("(//input[@type='checkbox'])[2]")); ...

Selenium WebDriver 使用瀏覽器的本地方法與 Web 組件進(jìn)行交互。盡管如此,有時(shí) Web 組件不會(huì)對(duì)這些本機(jī)方法做出反應(yīng)。在這種情況下,最可靠的選擇是 JavaScript。


因此,您可以嘗試使用以下 JavaScript 與 Web 元素進(jìn)行交互,


WebElement element = driver.findElement(By.cssSelector("input[value='Add/Update Network Security']"));


((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);

你也可以試試DebanjanBWebDriverWait說的。


查看完整回答
反對(duì) 回復(fù) 2023-06-08
?
慕婉清6462132

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

您可以使用xpath,并用于WebDriverWait使元素存在然后使用Actions,試試這個(gè):


new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@type='checkbox' and contains(@id,'permissions')]")));

WebElement elmnt = driver.findElement(By.xpath("//*[@type='checkbox' and contains(@id,'permissions')]"));

Actions act = new Actions(driver);

act.moveToElement(elmnt).click().build().perform();

或者


new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("(//*[@type='checkbox'])[1]")));

WebElement elmnt = driver.findElement(By.xpath("(//*[@type='checkbox'])[1]"));

Actions act = new Actions(driver);

act.moveToElement(elmnt).click().build().perform();

如果您想要另一個(gè)復(fù)選框,請(qǐng)將其更改[1]為等。[2]


查看完整回答
反對(duì) 回復(fù) 2023-06-08
?
森欄

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

您可以使用 uncle 元素的文本。要Select all下,Select permissions你可以使用

//li[contains(., 'Select permissions')]/following-sibling::li/label


查看完整回答
反對(duì) 回復(fù) 2023-06-08
  • 4 回答
  • 0 關(guān)注
  • 227 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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