按钮单击Selenium

时间:2016-11-14 20:42:21

标签: python selenium-chromedriver

我正在尝试在Selenium中测试图像按钮。

图像是事件,当我点击sgt消息时出现

HTML CODE:

<div class="jcrm-botondetalle">
    <a href="https://www.example.dsa.eu/ConsultaExample/">
       <img src="./../../img/entrar.png" class="jcrm-img1">
    </a>
</div>


# -*- coding: utf-8 -*- 
from selenium import webdriver
from datetime import time
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
try:
    import Image, ImageEnhance, ImageFilter    
except ImportError:
    from PIL import Image, ImageEnhance, ImageFilter    
import pytesseract

def evert_init():
    BaseUrl = "https://www.example.dsa.eu/"
    UrlDirection= BaseUrl + "seccion/servicios/detalles/0/c3.html"
    driver = webdriver.Chrome('/home/developer/lear-seleniun/chromedriver')  
    driver.get(UrlDirection)
    driver.find_element_by_css_selector("jcrm-img1")

evert_init()

2 个答案:

答案 0 :(得分:0)

driver.find_element_by_css_selector("jcrm-img1").click()

应该向该选择器返回的元素发送click事件。

答案 1 :(得分:0)

解决方案是使用类方法,它对我有用

submit=driver.find_element_by_class_name("jcrm-img1")
submit.click()