代码之家  ›  专栏  ›  技术社区  ›  Dima Bokov

如何通过java selenium定位相关的webElement

  •  1
  • Dima Bokov  · 技术社区  · 7 年前

    请参阅以下附件 enter image description here

        //Set date range
        WebElement parentStartdate = obj.findElement(By.xpath("//[@id=typein_[Parameters].[Parameter 3]]"));
        WebElement child=parentStartdate.findElement(By.xpath("//input[@value='1/1/2019']"));
    

    线程“main”org.openqa.selenium.InvalidSelectorException中出现异常:选择器无效:由于以下错误,无法找到xpath表达式为/[@id=typein.[Parameters].[Parameter 3]]的元素: SyntaxError:未能对“文档”执行“评估”:字符串“/[@id=typein.[Parameters].[Parameter 3]]”不是有效的XPath表达式。

    enter image description here

    整个xml结构: enter image description here

    3 回复  |  直到 7 年前
        1
  •  1
  •   Sameer Arora    7 年前

    WebElement element = driver.findElement(By.xpath("//input[@class='QueryBox']"));

        2
  •  1
  •   Mate MrÅ¡e    7 年前

    正如错误消息所说,这不是有效的Xpath表达式。按选择第一个元素

    WebElement parentStartdate = obj.findElement(By.xpath("//span[@class='TypeInQuerySpan']/input"));
    
        3
  •  1
  •   Constantin Trepadus    7 年前

    请尝试此选择器:

    //div[contains(@class, 'TypeInDiv')]/span[@class="TypeInQuerySpan"]/input[@type='text'][@class='QueryBox'][@value='1/1/2019']