Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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
如何在selenium中处理a标记_Selenium_Xpath_Css Selectors_Webdriverwait_Linktext_Java_Python - Fatal编程技术网

如何在selenium中处理a标记

如何在selenium中处理a标记,selenium,xpath,css-selectors,webdriverwait,linktext,java,python,Selenium,Xpath,Css Selectors,Webdriverwait,Linktext,Java,Python,我在selenium中面临以下标签的问题 HTML代码是: <a data-v-4sa1sads href='#' class='second'>Register</a> 我尝试使用LinkText,PartialLinkText,CSS选择器,Xpath,但总是显示一个错误,元素点击被截获 如何处理此问题。要单击要使元素成为可单击的元素(),您可以使用以下任一选项: 使用和linkText: new WebDriverWait(driver, 20).until

我在selenium中面临以下标签的问题

HTML代码是:

<a data-v-4sa1sads href='#' class='second'>Register</a>

我尝试使用
LinkText
PartialLinkText
CSS选择器
Xpath
,但总是显示一个错误,元素点击被截获


如何处理此问题。

要单击要使
元素成为可单击的元素()
,您可以使用以下任一选项:

  • 使用和
    linkText

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Register"))).click();
    
  • 使用和
    XPATH

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='second' and text()='Register']"))).click();
    
  • 使用和链接文本:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Register"))).click()
    
  • 使用和
    CSS\u选择器

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.second[href]"))).click()
    
  • 注意:对于python客户端,您必须添加以下导入:

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

工具书类 您可以在中找到关于以下内容的两个相关详细讨论:


您还可以添加周围的HTML吗?可能不是元素,而是其他一些元素接收单击事件