ν μ€νΈλ₯Ό μνλ μ리먼νΈμ νΉμ ν Attribute, Text, Size, CssSelector λ±μ μμ±λ€μ μμμΌν λκ° μλ€. μ΄λ μ¬μ©ν μ μλ λ©μλμ λν΄ κ³΅λΆν΄λ³΄μ.
getAttribute()
getAttribute() λ©μλλ λͺ¨λ μΉ μ리먼νΈμ μ¬μ© κ°λ₯νλ€. μμ± μ΄λ¦μ λ¬Έμμ΄ νμ μ μΈμλ‘ λ°λλ€. λ°ν νμ λ μμ±κ°μ λ¬Έμμ΄λ‘ λ°ννλ€.
μλλ λ€μ΄λ² ννμ΄μ§μ κ²μ νλ(μ λ ₯μ°½) Elementμ΄λ€.
<input id="query" name="query" type="text" title="κ²μμ΄ μ
λ ₯" maxlength="255" class="input_text" tabindex="1"
accesskey="s" style="ime-mode:active;" autocomplete="off" placeholder="κ²μμ΄λ₯Ό μ
λ ₯ν΄ μ£ΌμΈμ." onclick="documen
t.getElementById('fbm').value=1;" value="" data-atcmp-element="">
ν΄λΉ μ리먼νΈμ μμ±κ°μ μκ³ μΆμ κ²½μ°, μλμ κ°μ΄ μΆλ ₯ν΄λ³Ό μ μλ€.
public void elementGetAttributesExample() {
WebElement searchBox = driver.findElement(By.name("query"));
System.out.println("Name of the box is: "
+ searchBox.getAttribute("name"));
System.out.println("Id of the box is: "
+ searchBox.getAttribute("id"));
System.out.println("Class of the box is: "
+ searchBox.getAttribute("class"));
System.out.println("Placeholder of the box is: "
+ searchBox.getAttribute("placeholder"));
}
getText()
getText μ‘μ μ λͺ¨λ μ리먼νΈλ₯Ό λμμΌλ‘ μ€νν μ μλ€. μ리먼νΈκ° ν μ€νΈλ₯Ό νμνκ³ μμΌλ©΄ ν μ€νΈλ₯Ό κ·Έλλ‘ λ³΄μ¬μ£Όκ³ , μμΌλ©΄ μ무κ²λ λ°ννμ§ μλλ€.
λ€μμ λ€μ΄λ² ννμ΄μ§ μλ¨μ 곡μ§μ¬ν λ΄μ©μ κ°μ Έμ€λ μμ μ΄λ€. μλμλ μ΄ν΄λ¦½μ€μμ κ²°κ³Ό νλ©΄μ΄ μλ€.
public void elementGetTextExample() {
WebElement siteNotice = driver.findElement(By
.className("_3VkgqBXB"));
System.out.println("Complete text is: "
+ siteNotice.getText());
}
getCssValue()
getCssValue() λ©μλλ λͺ¨λ μΉ μ리먼νΈλ₯Ό λμμΌλ‘ μ¬μ© κ°λ₯νλ€. μ리먼νΈμμ ν°νΈ, λ°°κ²½μ, μμ λ±μ CSSμμ±κ°μ κ°μ Έμ¨λ€.
μλ ν μ€νΈ μ½λλ‘ κ²μμ°½μ font-familyλ₯Ό κ°μ Έμ¨λ€.
public void elementGetCssValueExample() {
WebElement searchBox = driver.findElement(By.name("query"));
System.out.println("Font of the box is: "
+ searchBox.getCssValue("font-family"));
}
getLocation() μ getSize()
λλ€ λͺ¨λ μ리먼νΈλ₯Ό λμμΌλ‘ μ€ν κ°λ₯νλ€.
- getLocation : μ리먼νΈμ μλ μμΉλ₯Ό (x,y)μ’νλ‘ κ°μ Έμ¬ μ μλ€. (μΌμͺ½ μκ° (0,0)μΌλ‘ κ°μ )
- getSize : μ리먼νΈμ λλΉμ λμ΄λ₯Ό λ°ν
κ²μμ°½μ μλμμΉμ μ¬μ΄μ¦λ₯Ό μ μ μλ μ½λλ₯Ό μμ±ν΄λ³΄μ.
public void elementLocationAndSizeExample() {
WebElement searchBox = driver.findElement(By.name("query"));
System.out.println("Location of the box is: "
+ searchBox.getLocation());
System.out.println("Size of the box is: "
+ searchBox.getSize());
}
getTagName()
getTagName() λ©μλλ λͺ¨λ μ리먼νΈμμ μν κ°λ₯νλ€. μΈμλ μκ³ , μΉ μ리먼νΈμ νκ·Έ μ΄λ¦μ λ°ννλ€.
μλ μ½λλ λ€μ΄λ² κ²μ λ²νΌμ νκ·Έ μ΄λ¦μ λ°ννλ μ½λμ΄λ€.
public void elementGetTagNameExample() {
WebElement searchButton = driver.findElement(By.className("btn_submit"));
System.out.println("Html tag of the button is: "
+ searchButton.getTagName());
}
'SQA > Automation' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Selenium μ리먼νΈμ μν νμΈ, νμ±ν λΉνμ±ν ν΄λ¦ κ°λ₯ μ¬λΆ (0) | 2023.04.21 |
---|---|
Selenium μ¬μ©μ μ‘μ μ€ν sendKey clear submit (0) | 2023.04.20 |
Selenium μλ¦¬λ¨ΌνΈ μμ κ° κ°μ Έμ€κΈ° By μ§μ μ, java (0) | 2023.04.18 |
Selenium μΉ μλ¦¬λ¨ΌνΈ μ°ΎκΈ° FindElement , java (0) | 2023.04.16 |
Maven νλ‘μ νΈ μμ± TestNG class μμ± λ°©λ² μμ (0) | 2023.04.14 |