Ejemplo 1: obtener atributo en selenium python
org = driver.find_element_by_xpath('//a[@class="cbtn--s"]')
val = org.get_attribute("href")
Ejemplo 2: obtener texto frente a obtener atributo en selenio
differences between getText() vs getAttribute("attribute");
-> getText();
-> returns the TEXT of the given web element.
-> return type is STRING
-> it does not accept any arguments.
-> it will return the text that is in between the opening tag and
the closing tag.
EX: <a href="https://facebook.com"> FACEBOOK </a>
-> What will getText() method return?
- return -> FACEBOOK
-> getAttribute("attribute");
- It will return the value of given attribute
- Return type is STRING
- It accepts a String arg
EX: <a href="https://facebook.com" class="om56"> FACEBOOK </a>
-> webelement.getAttribute("href") --> https://facebook.com
-> webelement.getAttribute("class") --> om56
.getCssValue("cssAttribute")
-> This method will return the value of given CSS attribute: such as,
font-size, font-style, color etc...
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)