λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

SQA/Automation

Selenium μ—˜λ¦¬λ¨ΌνŠΈ 속성 κ°€μ Έμ˜€κΈ° HTML get 속성 , java

ν…ŒμŠ€νŠΈλ₯Ό μ›ν•˜λŠ” μ—˜λ¦¬λ¨ΌνŠΈμ˜ νŠΉμ •ν•œ 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());
}