UnityNewb UnityNewb - 2 months ago 22
Python Question

Selenium Python Webdriver chrome print src's of all imgs

I want to print all src of imgs in the page, i want to see if it recognize it,
cuz when i do

driver.find_element_by_xpath("//img[@src='http://images.yad2.co.il/Pic/site_images/yad2/MyYad2/images/myorderbottom/new/jump_ad.png'").click()


its says:

C:\Users\Bar\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Bar/PycharmProjects/yad2/Webdriver.py
Traceback (most recent call last):
File "C:/Users/Bar/PycharmProjects/yad2/Webdriver.py", line 14, in <module>
driver.find_element_by_xpath("//img[@src='http://images.yad2.co.il/Pic/site_images/yad2/MyYad2/images/myorderbottom/new/jump_ad.png'").click()
File "C:\Users\Bar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\Bar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Users\Bar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Users\Bar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //img[@src='http://images.yad2.co.il/Pic/site_images/yad2/MyYad2/images/myorderbottom/new/jump_ad.png' because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//img[@src='http://images.yad2.co.il/Pic/site_images/yad2/MyYad2/images/myorderbottom/new/jump_ad.png'' is not a valid XPath expression.
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.1.7601 SP1 x86_64)


I have tried with
css_selector
, didn't work , so I want to print all of the srcs of the
imgs
, how can I do that?

Answer

Ok propably @Saurabh Gaur were right there is Iframe in the site , Simple solution ,

driver.switch_to.frame(driver.find_element_by_id("FrameID"))

Thats it from there i could find the button , then i comeback

driver.switch_to.default_content()

and from here i can continue to the next Frame Thats it! @Saurabh Gaur Thank you So much! , you were Excellent!

Comments