溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

WebDriver-元素的Actions

發(fā)布時間:2020-07-04 19:11:41 來源:網(wǎng)絡(luò) 閱讀:621 作者:honzhang 欄目:軟件技術(shù)

1.sendKeys()

適用于具備文本編輯區(qū)域的頁面元素。常見的使用方式是在文本框中輸入字符串。

driver.findElement(By.xpath("html/body/div[8]/div/div/input")).sendKeys("150");

如果希望在文本框中輸入某些特殊字符,如Shift,則需使用WebDriver中的Keys類。Keys是一個數(shù)組類,用于模擬多種不同的特殊按鍵輸入。例如:希望輸入大寫字母 ,手工的方式是先按住Shift鍵 然后輸入相應(yīng)的字母。

WebElement we1 = driver.findElement(By.xpath(".//*[@id='EXAM']/div[1]/h5/i"));

we1.sendKeys(Keys.chord(Keys.SHIFT,"webdriver"));


2.clear()

適用于具備文本編輯區(qū)域的頁面元素,作用是清除文本編輯區(qū)域中輸入的文本信息。

WebElement we1 = driver.findElement(By.xpath(".//*[@id='EXAM']/div[1]/h5/i"));

we1.clear();


3.submit()

適用于form或者form中的頁面元素,作用是提交form到Web的服務(wù)器端。

        WebElement we1 = driver.findElement(By.xpath(".//*[@id='EXAM']/div[1]/h5/i"));

        we1.submit();


4.isDisplayed()

適用于任意的頁面元素,用于判斷該元素是否在頁面上可見 。

        WebElement we1 = driver.findElement(By.xpath(".//*[@id='EXAM']/div[1]/h5/i"));

        System.out.println(we1.isDisplayed());


5.isEnabled()

適用于任意的頁面元素,用于判斷元素是否為啟用狀態(tài)。

        WebElement we1 = driver.findElement(By.xpath(".//*[@id='EXAM']/div[1]/h5/i"));

        System.out.println(we1.isEnabled());


6.isSelected()

適用于單選按鈕、多選按鈕,以及選項等頁面元素,用于判斷某個元素是否被選中。如果在其他頁面元素上調(diào)用該方法,程序會返回false.

        WebElement we1 = driver.findElement(By.xpath(".//*[@id='EXAM']/div[1]/h5/i"));

        System.out.println(we1.isSelected());


7.getAttribute()

適用于任意的頁面元素,用于獲取當前頁面元素的屬性。

        WebElement aboutGenExam = driver.findElement(By.linkText("聯(lián)系我們"));

        System.out.println(aboutGenExam.getAttribute("value"));


8.getText()

適用于任意的頁面元素,用于獲取元素上的可見文本內(nèi)容。如果文本內(nèi)容為空,則返回空。

        WebElement aboutGenExam = driver.findElement(By.linkText("聯(lián)系我們"));

        System.out.println(aboutGenExam.getText());


9.getTagName()

適用于任意的頁面元素,用于獲取元素的tag name。

        WebElement aboutGenExam = driver.findElement(By.linkText("聯(lián)系我們"));

        System.out.println(aboutGenExam.getTagName());


10.getCssValue()

適用于任意的頁面元素,用于獲取當前頁面元素的CSS屬性信息,如:cursor \font-family\font-size\height\background-color\background-p_w_picpath等。

        WebElement aboutGenExam = driver.findElement(By.linkText("聯(lián)系我們"));

        System.out.println(aboutGenExam.getCssValue("height"));


11.getLocation()

適用于任意的頁面元素,用于獲取元素在頁面上的相對位置 ,其中坐標系原點位于頁面的左上角。 該方法的返回值是一個包括(x,y)的坐標信息。

        WebElement aboutGenExam = driver.findElement(By.linkText("聯(lián)系我們"));

        System.out.println(aboutGenExam.getLocation());


12.getSize()

適用于任意可見的頁面元素,用于獲取元素的寬度和高度信息。其返回值是一個包括(width,height)的長寬組合。

        WebElement aboutGenExam = driver.findElement(By.linkText("聯(lián)系我們"));

        System.out.println(aboutGenExam.getSize());

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI