Apr-22-2019, 03:38 PM
(Apr-22-2019, 12:03 PM)buran Wrote:find_element_by_
methods will return just one/first element You need to usefind_elements_by_
methods that will return list of multiple elements then you will iterate over the elements in the list and extract .text property Locating elements docs
Hi buran, thanks you for your answer even Larz60+ has showed another way of using BS.
I tried your method to change from "element" to "elements"
case 1: news3 = browser.find_elements_by_xpath("//div[@class='hc_sr_summary']/div/div/h3/a").text
however, the error showed as AttributeError: 'list' object has no attribute 'text'
case 2: I removed the text as news3 = browser.find_elements_by_xpath("//div[@class='hc_sr_summary']/div/div/h3/a")
however, the result showed some element codes which are not found in the web.
Would you share more the proper way of using find_elements_by_xpath in this case? Thank.
[<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="c8f60e25-62c6-438d-98dc-25a7e9779656", element="af4e5737-265e-4920-a2a5-cbfaa97646fa")>, <selenium.webdriver.firefox.webelement.FirefoxWebElement (session="c8f60e25-62c6-438d-98dc-25a7e9779656", element="1cfb5db4-0f5f-4a20-8ddb-3fa93903b60c")>, <selenium.webdriver.firefox.webelement.FirefoxWebElement (session="c8f60e25-62c6-438d-98dc-25a7e9779656", element="61e02d61-36c6-470c-9dad-b0e053979172")>,