Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何单击拒绝单击的可用按钮?_Python_Selenium - Fatal编程技术网

Python 如何单击拒绝单击的可用按钮?

Python 如何单击拒绝单击的可用按钮?,python,selenium,Python,Selenium,我正在研究一个网站的自动化。我的问题是,selenium中可见的按钮(只是打印出来)在最近的更新后停止工作。即使我能看到它,我也不能点击它。我注意到它已经开始有动态id选择器,但类保持稳定。那会是什么?还有其他方法可以点击它吗 <div> <div> <div class="pull-left middle-col-4"> <!----> </div> &l

我正在研究一个网站的自动化。我的问题是,selenium中可见的按钮(只是打印出来)在最近的更新后停止工作。即使我能看到它,我也不能点击它。我注意到它已经开始有动态id选择器,但类保持稳定。那会是什么?还有其他方法可以点击它吗

<div>
    <div>
        <div class="pull-left middle-col-4">
            <!---->
        </div>
        <div class="pull-left middle-col-4">
            <!---->
        </div>
    </div>
    <button tabindex="-1" id="exit-button-ZpyYaHCdmZ5jnmaamGhjaJjFcsVrmJOUcZWVaZlsaGlolpOaZg" class="btn btn-inverse btn-large pull-right">Wyjście</button>
</div>

Wyjście

如果id是动态的,请找到下面的解决方案,单击退出按钮

1。Xpath和contains方法

button=driver.find_element_by_xpath("//button[contains(text(), 'Wyjście')]")
button.click()
2。类名

element = driver.find_element_by_class_name("btn btn-inverse btn-large pull-right")
element.click()

如果id是动态的,请找到下面的解决方案,单击退出按钮

1。Xpath和contains方法

button=driver.find_element_by_xpath("//button[contains(text(), 'Wyjście')]")
button.click()
2。类名

element = driver.find_element_by_class_name("btn btn-inverse btn-large pull-right")
element.click()

点击按钮,使
WebDriverWait
元素可点击
()并遵循定位器策略

通过Css选择器:

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-inverse.btn-large.pull-right"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='btn btn-inverse btn-large pull-right' and starts-with(@id,'exit-button-')][text()='Wyjście']"))).click()
通过Xpath:

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-inverse.btn-large.pull-right"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='btn btn-inverse btn-large pull-right' and starts-with(@id,'exit-button-')][text()='Wyjście']"))).click()
您需要导入以下内容以执行上述代码

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

点击按钮,使
WebDriverWait
元素可点击
()并遵循定位器策略

通过Css选择器:

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-inverse.btn-large.pull-right"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='btn btn-inverse btn-large pull-right' and starts-with(@id,'exit-button-')][text()='Wyjście']"))).click()
通过Xpath:

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-inverse.btn-large.pull-right"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='btn btn-inverse btn-large pull-right' and starts-with(@id,'exit-button-')][text()='Wyjście']"))).click()
您需要导入以下内容以执行上述代码

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

你能提供你的HTML DOM结构并解释哪个按钮是可见的吗?如果你能说出你想要达到的目标,那就太好了。如果存在动态id,则使用selenium contains方法来标识元素,或者,如果元素根据您的注释是稳定的,则可以使用类定位器来标识元素,然后单击该元素。@Rock edited。id是可更改的,类保持稳定。我需要点击它。此选择器在更新之前工作,并且仍然作为打印元素可见,因此必须有效。请显示selenium代码的示例,并描述运行该代码时发生的情况。如果您遇到任何错误,请务必显示这些错误。您能否提供您的HTML DOM结构并解释哪个按钮是可见的?如果你能说出你想要达到的目标,那就太好了。如果存在动态id,则使用selenium contains方法来标识元素,或者,如果元素根据您的注释是稳定的,则可以使用类定位器来标识元素,然后单击该元素。@Rock edited。id是可更改的,类保持稳定。我需要点击它。此选择器在更新之前工作,并且仍然作为打印元素可见,因此必须有效。请显示selenium代码的示例,并描述运行该代码时发生的情况。如果您有任何错误,请务必显示这些错误。如果您的问题得到解决,请接受并向上投票。投票结果将相同。正如我提到的,按钮是可见的,但selenium并没有点击它。它有点安全了。@sinsuoida你说的“selenium不点击它”是什么意思?发生了什么事?@Sinsuoida如果可能,请访问您的网站。如果您的问题得到解决,请接受并投票表决答案。投票结果相同。正如我提到的,按钮是可见的,但selenium并没有点击它。它有点安全了。@sinsuoida你说的“selenium不点击它”是什么意思?发生了什么事?@Sinsuoida如果可能,请访问您的网站?