I am new to Python , Selenium and need some help on how to do this:
I am searching for certain things on a site and after searching, the results that are rendered are dynamic based on the search. I am trying to get the results set , but unable to on how to do it: Here's a part of the results page that the code has and I am trying to get all the listings. I specifically want to iterate through each listing and also want to get each listing code (1111111111 , 1111111112....)
<div id="listingsParent">
<div id="listings" class="visibleLayer">
<div>
<div id="listing_1111111111">
<div class="abc test">.......</div>
----
----
</div>
<div id="listing_1111111112">
<div class="abc test1">.......</div>
----
----
</div>
<div id="listing_1111111113">
<div class="abc test2">.......</div>
----
----
</div>
<div id="listing_1111111114">
<div class="abc test3">.......</div>
----
----
</div>
I have used the code:
allListings = browser.find_elements_by_xpath("//*[@id='listings']")
LisBegin = allListings.find_elements_by_xpath("//div[contains(text(), 'listing_']")
and then trying to get the attribute "id" .....listing_1111111111 which is not working for me.
Thank You for your help
Raj
You can achief this via xpath, all the elements that have a id that contain listing_
will match this xpath
LisBegin = allListings.find_elements_by_xpath("//div[contains(@id, 'listing_')]")
You can look at this for more information of xpath.
Also have a look at locators in selenium for more information about the different locators
I hope this will help you in your work, if you have any questions, don't hesitate to ask them.
Observation 1 : It has to be findelement and not findelements.
allListings = browser.find_element_by_xpath("//*[@id='listings']")
Observation 2 : use id instead of text.
LisBegin = allListings.find_elements_by_xpath("//div[contains(@id, 'listing_')]")
Hope this helps you. Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.