单击Python Selenium中特定行的表中的按钮
我有一个带有表格的页面和几行,其中一些行与其他行具有相同的文本 如果同一行中的文本包含单击Python Selenium中特定行的表中的按钮,python,selenium,xpath,webdriverwait,xpath-1.0,Python,Selenium,Xpath,Webdriverwait,Xpath 1.0,我有一个带有表格的页面和几行,其中一些行与其他行具有相同的文本 如果同一行中的文本包含real中的文本“real”,我想单击一个按钮“Delete” www.123.com 真实的 123.123.1.1 () 删除 www.123.com 事实上的 88.123.2.2 () 删除 您可以尝试以下xpath: //tr//td[@class="user_type" and text()="real"]//following-sibling::td//
real中的文本“real”,我想单击一个按钮“Delete”
www.123.com
真实的
123.123.1.1 ()
删除
www.123.com
事实上的
88.123.2.2 ()
删除
您可以尝试以下xpath:
//tr//td[@class="user_type" and text()="real"]//following-sibling::td//button[text()="Delete"]
当同一行包含文本real时,要单击文本为Delete的元素,您必须使
元素可单击()
,并且您可以使用以下任一方法:
- 使用
和具有class属性的以下同级:XPATH
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[@class='user_type' and text()='real']//following-sibling::td[@class='actions']//button[contains(., 'Delete')]"))).click()
- 使用
和以下索引同级:XPATH
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[@class='user_type' and text()='real']//following-sibling::td[2]//button[contains(., 'Delete')]"))).click()
- 注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC