lundi 23 mars 2015

Selenium code to extract text/find only visible elements with "one" class


I am having issues with selenium. I want to extract text of a visible element with the class "one".


Here is the html:



<div id="result-success" class="text-center displayed">
<h3 class="one">Success</h3>
<p class="two">Yes! I've found them!</p>
<div class="list-items"> <a href="mailto:ryan.johnson@target.com" title="Click here to directly send an email" class="label label-success three">


This is one of 4 possibilities. The other possibilities are not visible, but all have the class "one" in them. So how do I select only this element?


Do I have to use jquery? I want to extract the text within this class, so the text "Success" as well as the email in the "list-items" class.


How do I do this? I don't think the site is written in jquery. My code is currently in python.


This is my code:



inputElement = browser.find_element_by_id("form-search-name")
inputElement.send_keys(leadslist[i][0])
inputElement = browser.find_element_by_id("form-search-domain")
inputElement.send_keys(leadslist[i][1])
searchbutton = browser.find_element_by_name("search")
searchbutton.click()


wait = WebDriverWait(browser, 10)

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "h3.one")))
msg=browser.execute_script("$('.one:visible').text()")
print(msg)




Aucun commentaire:

Enregistrer un commentaire