如何使用硒单击按钮-网站

时间:2020-09-27 10:54:49

标签: python selenium button click

我想在下面的代码中打开http,然后单击显示烛台的图形按钮。 这是因为然后我想执行屏幕截图并保存标题的图形图像。 你能帮我吗?


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

PATH="C:\Program Files (x86)\chromedriver.exe"
driver= webdriver.Chrome(PATH)
driver.get("https://www.plus500.it/Instruments/TSLA")


try:
    element=WebDriverWait(driver,30).until(EC.element_to_be_clickable(By.ID, "ButtonLine"))
    element.click()

except:
    print('not found')
    driver.quit()

2 个答案:

答案 0 :(得分:0)

您遇到的错误(但在尝试使用时没有出现...除外)是:

element=WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.ID, "ButtonLine")))

原因:您忘记了括号

修复:

  <div class="row login-box">
   <div class="col-sm-6">

   <!--Some default code-->

   <!--My code code-->
    <div class="or-seperator" style="margin:20px 0 10px;text-align: center; border-top: 2px solid #006400;">
     <i style="padding: 0 10px;background: #006400;position: relative; top: -11px;z-index: 1; color:white;">Or login with</i>
    <div>
        <a href="/index.php?route=account/login" style="text-decoration:none;padding:5px 20px"><b>Facebook</b></a>
        <a href="/index.php?route=account/login" style="text-decoration:none"><b>Google</b></a>
    </div>
 </div>
</div>

只需测试一下,它就可以正常工作。

答案 1 :(得分:0)

您可以找到元素并在.click()之后添加,如下所示:

find_element_by_xpath(xpath to element).click()