0

I'm trying to use selenium webdriver to assert a

logo.svg == context.driver.find_element_by_xpath("//img[@src='../logo.svg']"

on Python3.

So, when I'm running the testcase I get:

raise exception_class(message, screen, stacktrace)
      selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//img[@src='../logo.svg']"}

Snapshot of the HTML:

HTML

I been trying to "find" this particular image on a header with no success. Can anyone help me?

#---- reviwing the issue, logo_company = logo.svg is a string and context.driver.find_element_by..... it's the imagin object. I thinking how can i compare string == string or, maybe, the file.svg == context.driver that return file.svg something like that?

1 Answers1

0

The seems to be a bit off. To locate the element you can use either of the following Locator Strategies:

  • xpath A:

    context.driver.find_element_by_xpath("//img[starts-with(@src, '/static/media/logo-Caja-los-andes')]")
    
  • css_selector A:

    context.driver.find_element_by_css_selector("img[src^='/static/media/logo-Caja-los-andes']")
    
  • xpath B:

    context.driver.find_element_by_xpath("//img[starts-with(@src, '/static/media/logo-Caja-los-andes') and @alt='Logo Caja Los Andes']")
    
  • css_selector B:

    context.driver.find_element_by_css_selector("img[src^='/static/media/logo-Caja-los-andes'][alt='Logo Caja Los Andes']")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352