0

I am not able to derive the xpath for the following Text "Payment complete. Your policy will be generated soon". I have tried using the default xpath by directly copying the same but it throws the following error during execution invalid selector:

The result of the xpath expression "//*[@id="__next"]/div/div[1]/div[2]/div[1]/div[1]/span/text()" is: [object Text]. It should be an element.

Snapshot:

enter image description here

2
  • not sure how to accept answers... I am not aware of how stackoverflow works..sorry for the inconvenience caused Commented Jan 19, 2022 at 7:52
  • And again, we need a link or entire XML/HTML code here Commented Jan 19, 2022 at 8:12

1 Answer 1

1

The xpath expression...

//*[@id="__next"]/div/div1/div[2]/div1/div1/span/text( )

...returns a Text Node where as Selenium expects a WebElement.


To locate the element with text Payment complete. Your policy will be generated soon you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH 1:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[text()[contains(.,'Payment complete')]]")))
    
  • Using XPATH 2:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[contains(., 'Your policy will be')]")))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.