代码之家  ›  专栏  ›  技术社区  ›  Petr Petrov

硒:点击按钮

  •  0
  • Petr Petrov  · 技术社区  · 5 年前

    它是 html

    <div class="add-company-form__form-control add-company-form__submit">
        <button class="button button_theme_islands button_size_xl button_view_action button_type_submit button__control i-bem" data-bem='{"button":{}}' role="button" type="submit">
            <span class="button__text">Добавить организацию</span>
        </button>
    </div>
    

    我试着用

    driver.find_element_by_xpath("//div[@class='add-company-form__submit']/button").click()
    

    但它又回来了

    NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='add-company-form__submit']/button"}
    

    0 回复  |  直到 5 年前
        1
  •  0
  •   Mate MrÅ¡e    5 年前

    您应该尝试在单击按钮之前实例化一个WebDriver wait:

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(By.XPATH, "//button[@class='button button_theme_islands button_size_xl button_view_action button_type_submit button__control i-bem']"));
    

    注:

        2
  •  1
  •   KunduK    5 年前

    尝试使用Xpath。

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='button button_theme_islands button_size_xl button_view_action button_type_submit button__control i-bem']")))
    

       WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.button_theme_islands")))