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 Selenium中特定行的表中的按钮_Python_Selenium_Xpath_Webdriverwait_Xpath 1.0 - Fatal编程技术网

单击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的元素,您必须使
元素可单击()
,并且您可以使用以下任一方法:

  • 使用
    XPATH
    和具有class属性的以下同级:

    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