In my current exercise, I am using the cssGetValue method to extract the value from a specific web element's CSS property.
I have two main inquiries:
Why did the cssGetValue method return the value 13px, and which exact web element is being referenced by this method? 1a. To retrieve the CSS property for the section labeled as "By ID," how can I adjust my code in order to obtain the CSS property value for the id="by-id" section?
Although I used the driver.close() method, it did not successfully close the browser upon script completion. Can you please clarify why the driver.close() method failed to work in this particular scenario?
Below is a segment of my code:
package wd_findElementBy; import java.util.List; import org.junit.Test; import org.junit.Before; import org.junit.After; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class SearchWebElements { WebDriver driver = new FirefoxDriver(); private String baseUrl= "http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example"; @Test public void findElements(){ driver.get(baseUrl); try{ List<WebElement> elements = driver.findElements(By.id("by-id")); System.out.println("number of elements: " + elements.size()); for(WebElement ele : elements){ System.out.println(ele.getTagName()); System.out.println("get the text for web element with id='by-id'"); System.out.println("----------------------------------------------"); System.out.println(ele.getText()); System.out.println("----------------------------------------------"); System.out.println(ele.getAttribute("id")); System.out.println(ele.getCssValue("font-size")); } } finally{ //driver.close(); driver.quit(); } } }