Selenium web驱动程序:找不到元素

Selenium web驱动程序:找不到元素,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我不熟悉selenium:我有这个源代码,正在尝试使用xpath和SeleniumWebDriver单击一个按钮。这是我试图单击的按钮(html中的最后一行): 我使用这个xpath:“//div[@id='innerBody']/div[4]/div/div/ul/li[3]/button” 它让我无法定位元素 知道为什么,我该怎么做吗 <document> <html class="FullPage" xmlns="http://www.w3.org/1999/xhtml

我不熟悉selenium:我有这个源代码,正在尝试使用xpath和SeleniumWebDriver单击一个按钮。这是我试图单击的按钮(html中的最后一行):

我使用这个xpath:
“//div[@id='innerBody']/div[4]/div/div/ul/li[3]/button”
它让我无法定位元素

知道为什么,我该怎么做吗

<document>
<html class="FullPage" xmlns="http://www.w3.org/1999/xhtml" style="">
<head>
<body class="brand brand-mastwide FullPage no-footer width-hd" style="">
<div id="cboxOverlay" style="display: none;"/>
<div id="colorbox" class="" style="padding-bottom: 2px; padding-right: 2px; display: none;">
<div id="masthead" class="masthead full-width">
<div id="toast-absolute" class="full-width">
<!-- Content -->
<div id="outer-outer" class="with-nav">
<div id="outer-wrapper" class="full-width">
<a name="pageTop"/>
<div class="main-wrapper">
<div class="inner">
<div id="applicationHost">
<div data-bind="router: router" data-view="_App/AppShell" style="" data-active-view="true">
<div class="durandal-wrapper" data-view="_App/Home/HomeShell" style="" data-active-view="true">
<link rel="stylesheet" href="/cache/sf/_App/Home/HomeShell.css"/>
<link rel="stylesheet" href="/cache/sf/css/lib/joyride-2.1.css"/>
<div id="regionMain" class="clear-block with-side with-side-left" data-bind="css:{'clear-block with-side with-side-left': ShowLeftNavigation()}">
<div class="content-pane main">
<div class="inner-content-pane main">
<div data-bind="compose: Message"/>
<div class="router" data-bind="router: router">
<div class="durandal-wrapper" data-view="_App/Home/Filebox/Filebox" style="" data-active-view="true">
<h1 data-bind="text: Title">Bestandsvak voor satish vanahalli</h1>
<link href="/cache/f69bb3f534fb459062226526576bc4dea7e8fe7e/css/lib/jqui/jquery-ui-1.10.0.sf.css" type="text/css" rel="stylesheet"/>
<br/>
<div id="innerBody" class="file-box-container">
<div class="errortip" data-bind="text: ErrorMessage, visible: ErrorMessage" style="display: none;"/>
<div class="clear-block">
<div class="upload-button">
<div data-bind="compose: FileList">
<div class="c-content" data-view="_App/Home/Common/FileList/FileList" style="" data-active-view="true">
<div class="secondary-ctrl btnl-row title-noborder clear-block" data-bind="css: { hidden: !ShowSecondary }">
<ul class="context-actions" data-bind="visible: Capabilities.AllowCheckboxes, foreach: CurrentActions">
<li class="hover-list">
<li class="hover-list">
<li class="hover-list">
***<button class="txt context-action" data-bind="click: Click">***

贝斯坦斯瓦克·沃奥尔·萨蒂什·瓦纳哈利

  • ******
试试这个xpath:

//*[@id="innerBody"]/div/div/div/div/div/div/ul/li[3]/button
请尝试以下xpath:

//*[@id="innerBody"]/div/div/div/div/div/div/ul/li[3]/button

根据您对问题的评论,如果您想单击列表中的第三个按钮,请尝试下面的xpath;我刚刚调整了莎莉莎的:

(//button[@class='txt context-action'])[3]

这将单击页面中的第三个按钮(按DOM表示的时间顺序),其中
class
as
txt context action

,根据您对问题的评论,如果您想单击列表中的第三个按钮,请尝试下面的xpath;我刚刚调整了莎莉莎的

(//button[@class='txt context-action'])[3]
这将使用
class
作为
txt上下文操作单击页面中的第三个按钮(按DOM表示的时间顺序),尝试以下xpath:

   //ul[@class='context-actions']/li[3]/button[@class='txt context-action][3]
请尝试以下xpath:

   //ul[@class='context-actions']/li[3]/button[@class='txt context-action][3]


您使用过这个xpath:*//按钮[@class='txt context action]**这很有趣。尝试了这个,它正在单击列表中的第一个按钮。如何定位列表中的第三个按钮?父div标记中有多少个按钮?您可以发布其他按钮的html代码吗?您是否使用了此xpath:*//按钮[@class='txt context action]**这很有趣。尝试了这个,它正在单击列表中的第一个按钮。如何定位列表中的第三个按钮?父div标记中有多少个按钮?您可以发布其他按钮的html代码吗?尝试此按钮,给出相同的错误无法定位element@Virus:按钮是否异步加载?可能使用ajax?尝试过这个,给出同样的错误无法定位element@Virus:按钮是否异步加载?也许是ajax?我是否在括号中给出了它?它给出了“无效或不会导致web元素”错误Yes。。在使用Java进行编码的情况下,单击元素的代码必须如下所示:
driver.findElement(By.xpath((//button[@class='txt context action])[3]”)太好了!现在可以工作了,这是复制粘贴错误。我的错!我错过了在结尾处为这个“txt上下文操作”添加一个引用。感谢您对Subh和@SarithaMark@Saritha的回复。。她是第一个弄明白的人。。我刚刚调整了她的答案。。当然要引用“女士优先”这句话谢谢你的慷慨:)我把它放在括号里了吗?它给出了“无效或不会导致web元素”错误Yes。。在使用Java进行编码的情况下,单击元素的代码必须如下所示:
driver.findElement(By.xpath((//button[@class='txt context action])[3]”)太好了!现在可以工作了,这是复制粘贴错误。我的错!我错过了在结尾处为这个“txt上下文操作”添加一个引用。感谢您对Subh和@SarithaMark@Saritha的回复。。她是第一个弄明白的人。。我刚刚调整了她的答案。。当然要引用“女士优先”这句话谢谢你的慷慨:)将此作为第一条评论的答案几乎给了我答案。感谢@Subh对其进行调整,我很高兴它对您有所帮助。。!!将此标记为答案作为第一条评论几乎给了我答案。感谢@Subh对其进行调整,我很高兴它对您有所帮助。。!!