Clicking an element on an overlay table using Python Selenium?

Question:

I am trying to create a workaround to click the first element in a table on a website that has an overlay table. The xpath does not appear to be related to the iframe, but I do not HTML.

The text does not link anywhere, but when clicked, it goes away and I can continue using the webpage.

The for loop goes through and searches vin numbers and gets prices, but some vins, for some odd reason are shared by the same vehicle with different trims. I am not comfortable sharing the table, but to describe it visually, it grays out the background, similar to a cookie alert and has entries representing the different clickable trims.

The code for detail.

for j in range(0,len(vins)):
  try:
    normal loop
  except:
    driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div[2]/div[1]/div/div/div/div/div[2]/div/div/div/div[3]/table/tbody/tr[1]/td[1]').click()

Error from query is InvalidArgumentException: invalid argument: invalid locator

Asked By: CaptOle

||

Answers:

The issue you’re encountering is that, when the first element in a table is not found, the code is trying to click on an element using an XPath locator, which is giving you an error.

To resolve this issue, you can try using the following code to catch the error and continue with the next iteration of the loop:

for j in range(0, len(vins)):
  try:
    # normal loop code
  except:
    try:
      driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div[2]/div[1]/div/div/div/div/div[2]/div/div/div/div[3]/table/tbody/tr[1]/td[1]').click()
    except:
      continue
Answered By: Timothy Alexis Vass