4.4. FindElement
Để tương tác với một đối tượng cụ thể trên 1 trang web ta sử dụng hàm
driver.findElement(By.class)
, hàm findElement
trả về đối tượng đầu tiên mà nó tìm thấy dựa trên By.class truyền vào. Nếu ko tìm được đối lượng nó sé trả về Error
Strategy
Syntax
Descriptions
By ID
driver.findElement(By.id(<element ID>))
Locates an element the using ID attribute
By Name
driver.findElement(By.name(<element name>))
Locates an element the using name attribute
By class name
driver.findElement(By.className(<element class>))
Locates an element the using class name attribute
By tag name
driver.findElement(By.tagName(<htmltagname>))
Locates an element using the HTML tag
By link text
driver.findElement(By.linkText(<linktext>))
Locates link using its text
By partial link text
driver.findElement(By.partialLinkText(<linktext>))
Locates link using it's partial text
By css
driver.findElement(By.cssSelector(<css selector>))
Locates element using the CSS selector
By Xpath
driver.findElement(By.xpath(<xpath query expression>))
Locates element using the Xpath selector
Last updated
Was this helpful?