Selenium can't get this class

I’m trying to get the button clicked but Selenium cant reach that class :

access-grants__flows-area__create-button container

key_cli_btn = self._get_xpath("//div[@class='/html/body/div/div/div[1]/div/div[3]/div/div[2]/div[2]/div[3]/div[4]/div'")

This xpath is invalid :

    selenium.common.exceptions.InvalidSelectorException: Message: invalid selector:    `Unable to locate an element with the xpath expression //div[@class='/html/body/div/div/div[1]/div/div[3]/div/div[2]/div[2]/div[3]/div[4]/div' because of the following error:

`SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘//div[@class=’/html/body/div/div/div[1]/div/div[3]/div/div[2]/div[2]/div[3]/div[4]/div” is not a valid XPath expression.

or I’ve tried to start from this div class:


but I don’t know how to get "child"

[![enter image description here][1]][1]


    def _get_xpath(self, xpath: str) -> webdriver:
    return self.driver.find_element(By.XPATH, xpath)

>Solution :

I have no idea what self._get_xpath is, but generally something like this probably should work:

key_cli_btn = driver.find_element(By.XPATH, "//div[@class='access-grants__flows-area__create-button container']")

Leave a Reply