0

I want to ask you kindly to help me out here with a basic issue. Can't click on a image that has these 2 caracters: a title and src link. I tried until now with XPATH:

".//*[@id='resultsTable']/tbody/tr[2]/td[11]/a[2]/img"

elmlupa=browser.find_element_by_xpath('//a[img/src="/common/images/Detail.gif"]').click()

"//img[@title='details']"
##LATER EDIT: I used even with the XPATH from firebug/firepath:
#sortam dupa decision date manual
#clicuim pe prima lupa
browser.implicitly_wait(2)
browser.switch_to.default_content()
browser.switch_to.frame("main")
browser.implicitly_wait(2)
time.sleep(10)
elmlupa = browser.find_element_by_xpath(".//*[@id='resultsTable']/tbody/tr[2]/td[11]/a[2]/img").click()

enter image description here

Thank you in advance!

Cohen
  • 944
  • 3
  • 13
  • 40

2 Answers2

1

Try below line of code:

elmlupa=browser.find_element_by_xpath('//a[img[@title="Details"]]').click()

Note that XPath is case-sensitive: "Details" != "details"

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Thank you @Andersson. I tried and still i receive the same error of not locating the picture of the 'loop". I tried even with the firebug/firepath XPATH and still i can't locate it. Do you know if the site have some kind of protection not to click on items? I have to say also that on the frame each row has the same loop details and maybe this creates the error? just because there are more than 20 loops with the same details on the page? – Cohen Jun 12 '17 at 20:06
  • Hi, I saw that all the resuls from the table are coming into an iframe. Does this changes somehow the game? so inside the main frame, the results are populating into an iframe. I think that this is why it couldn;t find the image. What do you think? – Cohen Jun 12 '17 at 21:58
  • Yes, to handle elements inside an `iframe` you should [switch to it](https://stackoverflow.com/questions/7534622/selecting-an-iframe-using-python-selenium/24286392#24286392) first. There are few possible ways how to handle `iframe`. Let me know if approach from provided link doesn't work for you – Andersson Jun 13 '17 at 04:09
  • Thank you @Andrersson! it worked! i had to tweak a bit to make it like this: iframe = browser.find_element_by_tag_name("iframe") browser.switch_to.frame(iframe). However when trying to click on the image from the new iframe :D i receive an error like \\\\selenium.common.exceptions.ElementNotInteractableException:\\\\ I don't understand what is this. I think that behind that image is a java o javascript that will open a new window when clicking the image. – Cohen Jun 13 '17 at 07:02
  • Can you share page `URL`? – Andersson Jun 13 '17 at 07:09
  • Hi Andersson, unfortunately i can't as is privately url where i have to login etc. I located the element with xpath elmlupa = browser.find_element_by_xpath(".//*[@id='resultsTable']/tbody/tr[2]/td[11]/a[2]/img").click() – Cohen Jun 13 '17 at 07:15
  • hi @Andresson, no is not working. by using xpath i still receive that error. Thank you! – Cohen Jun 13 '17 at 07:27
  • You'd better to open new ticket regarding new issue and add all related details – Andersson Jun 13 '17 at 07:40
0

Try below: browser.find_element_by_xpath('//img[@title="Details" and @src="/common/images/Detail.gif"]').click()

Also, in some cases you might need to click on the instead of an img.

sen4ik
  • 407
  • 4
  • 16
  • Thank you @sen4ik! i did this and still have the error. I think the issue comes from the fact that there are more than 20 pictures with the same title and same src code. This can create an issue? – Cohen Jun 12 '17 at 20:08
  • You can specify the index of the link you want to click image in '//a[1]/img[@title="Details" and @src="/common/images/Detail.gif"]' – sen4ik Jun 12 '17 at 20:48
  • Thank you @sen4ik! i just tried and still have the same error. the image is inside of a table...don't know if this would be a an issue, or maybe the site has some kind of protection. do you know how i can see if has a protection or not? – Cohen Jun 12 '17 at 20:56
  • Hi, I saw that all the resuls from the table are coming into an iframe. Does this changes somehow the game? so inside the main frame, the results are populating into an iframe. I think that this is why it couldn;t find the image. What do you think? – Cohen Jun 12 '17 at 21:59
  • Yes, it does changes the game. You have to switch to iframe first. Something like driver.switch_to.frame(driver.find_element_by_tag_name("iframe")). – sen4ik Jun 12 '17 at 22:04
  • Thank you @sen4ik! it worked! i had to tweak a bit to make it like this: iframe = browser.find_element_by_tag_name("iframe") browser.switch_to.frame(iframe). However when trying to click on the image from the new iframe :D i receive an error like \\\\selenium.common.exceptions.ElementNotInteractableException:\\\\ I don't understand what is this. Behind that image is a java o javascript that will open a new window when clicking the image. – Cohen Jun 13 '17 at 07:03
  • Try to click on the link tag instead of an img. – sen4ik Jun 14 '17 at 17:42