查找并单击按钮的click()函数

时间:2019-05-21 06:59:40

标签: python python-3.x selenium-webdriver

对于以下检查,我无法单击按钮“ MARK WEBATTENDANCE”

<div class="box1child" ng-show="markAttendance"><button ng-show="showMarkAttendance"  style="background-color:#398439;">MARK ATTENDANCE</button></div>
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Ie()


driver.get("https:*********/WebAttendance/index.html")

mark_webattendance = driver.find_element_by_xpath("//button[@ng-show='showMarkAttendance']")
mark_webattendance.click()

3 个答案:

答案 0 :(得分:0)

xpath的用法为//tagName[@attribute = 'value'],这是完全匹配的 //tagName[contains(text(), 'value')]用于包含值的字符串 另一个选项是//tagName[contains(@attribute, 'value')]

答案 1 :(得分:0)

mark_webattendance = driver.find_element_by_xpath(“ // button [包含(text(),'MARK ATTENDANCE')]”)) driver.implicitly_wait(10000) mark_webattendance.click()

答案 2 :(得分:0)

访问方式按钮-

var element = driver.find_element_by_xpath("//button[@id ='kk' and text()='MARK ATTENDANCE']");
driver.implicitly_wait(10000);
element.click();

OR

var element = driver.find_element_by_xpath("//button[text()='MARK ATTENDANCE']");
driver.implicitly_wait(10000);
element.click();

OR

var element = driver.find_element_by_xpath("//button[contains(text(), 'MARK ATTENDANCE')]");
driver.implicitly_wait(10000);
element.click();