首页 > 解决方案 > 单击使用 Selenium 启用 ember.js 的元素

问题描述

我正在尝试使用以下按钮在linkedin页面上单击selenium

<button id="ember607" class="share-actions__primary-action artdeco-button artdeco-button--2 artdeco-button--primary ember-view" data-control-name="share.post"><!---->
<span class="artdeco-button__text">
    
        Post
    
</span></button>

我曾尝试使用:

基本上,所有方法都会生成相同的错误消息:

Exception has occurred: NoSuchElementException
Message: no such element: Unable to locate element:{[*the_error_is_here*]}

我也尝试过 xpath contains() 方法,但这没有找到按钮。

请问点击这个按钮的正确方法是什么?

我正在使用3.9pythonwindows版本driver = webdriver.Chrome

标签: pythonseleniumxpathember.jscss-selectors

解决方案


有时,目前无法点击的按钮会出现问题。试试这个:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By


wait = WebDriverWait(driver, 10)

button = wait.until(EC.element_to_be_clickable((By.XPATH, '[YOUR X_PATH TO THE BUTTON]')))
driver.execute_script("arguments[0].click()", button)

这不是用硒单击任何按钮的最干净的方法,但对我来说,这种方法几乎每次都有效。


推荐阅读