Get Span Inside a Class Using Webdriver and Selenium

Get span inside a class using WebDriver and Selenium

You can simply use a CSS selector, and then print the text attribute of the span element:

contacts = browser.find_elements_by_css_selector('._32mo span')
for contact in contacts:
print(contact.text)

How to get the value of a span inside a li using Python Selenium webdriver?

The value of SCN i.e. 89862530 is reflected in 3 different places and you can extract it from either of the places inducing WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • <map-hs-label-value> tag with map-hs-lv-value attribute:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located()((By.XPATH, "//div[@class='hs-customerdata hs-customerdata-pvalues']/ul/li/map-hs-label-value"))).get_attribute("map-hs-lv-value"))
  • <span> tag with map-v-key attribute:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located()((By.XPATH, "//div[@class='hs-customerdata hs-customerdata-pvalues']/ul/li/map-hs-label-value//span[@class='hs-attribute-value']"))).get_attribute("map-v-key"))
  • <span> tag with text as 89862530:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located()((By.XPATH, "//div[@class='hs-customerdata hs-customerdata-pvalues']/ul/li/map-hs-label-value//span[@class='hs-attribute-value']"))).get_attribute("innerHTML"))

How to find all the span tag inside of an element in selenium python?

simply use .text

TargetElem = self.wait.until(EC.presence_of_element_located((By.ID, "textelem")))
print(TargetElem.text)

I do not think that you actually need a loop, since we are passing textelem id of div and all the span tags are inside the div, so .text should work.

Get text from <span> within a <div> with Selenium

You should target the <span> child

driver.find_element_by_css_selector(".unique_class_date > span").text

If this doesn't work either you can use get_attribute()

element = driver.find_element_by_css_selector(".unique_class_date > span")
element.get_attribute("textContent")
#or
element.get_attribute("innerText")

Java Selenium webdriver access span element inside each div element from a autosuggest

searchList = driver.findElements(By.xpath("//div[@class='acp']"))
for(int i = 0;i<searchList.size();i++) {
System.out.println(searchList.get(i).getText());

Just get all 8 dropdown values and then print it's getText.



Related Topics



Leave a reply



Submit