tetodenega
tetodenega

Reputation: 230

How to find the object using Selenium and Python

So I've used find_element_by_xpath to lacate diferent objects in the same html, using selenium.

But now I'm trying to find a specific element on the same html, always copying the xpath (chrome>inspect element>copy xpath) and I get the NoSuchElementException error.

The object is outside any iframe.

Heres the object that I'm trying to access:

<a class="carb-de-grid-name-link" data-index="1">CapLeads DataExtension_Copy</a>

And the whole html thing:

https://docs.google.com/document/d/1QfKlfYcH1y-aZ1oOZXzPwR1qeas7QjQDo0VeQOqdm-E/edit?usp=sharing

The python line:

link_data_extension_2=driver.find_element_by_xpath('//*[@id="dg-wrap"]/div[2]/div[2]/div[2]/div[1]/div[3]/div[2]/a')

I have already tried to hold the program and wait for the page to load (20s), nothing.

Any input is appreciated.

Upvotes: 0

Views: 69

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193108

To find the element with text as CapLeads DataExtension_Copy you can use either of the following solutions:

  • Using LINK_TEXT:

    link_data_extension_2 = driver.find_element_by_link_text("CapLeads DataExtension_Copy")
    
  • Using CSS_SELECTOR:

    link_data_extension_2 = driver.find_element_by_css_selector("a.carb-de-grid-name-link")
    
  • Using XPATH:

    link_data_extension_2 = driver.find_element_by_xpath("//a[@class='carb-de-grid-name-link' and text()='CapLeads DataExtension_Copy']")
    

Upvotes: 1

Related Questions