无法使用selenium webdriver在表中定位元素

无法使用selenium webdriver在表中定位元素,selenium,selenium-webdriver,xpath,webdriver,Selenium,Selenium Webdriver,Xpath,Webdriver,未使用selenium webdriver加载表内容。它只显示表的标题,而不显示内容 我已成功登录到我的应用程序中,但在主屏幕上有一个表,其中列出了某些项目,而使用selenium时,它不会加载表中的内容 硒罐:2.53 Mozilla Firefox版本:46.0 同样使用谷歌chrome浏览器,但也不起作用 当我关闭浏览器(selenium打开)并手动重新打开它时,它工作正常。但当selenium打开它并转到主页时,表数据不会加载 <div class="project-list-b

未使用selenium webdriver加载表内容。它只显示表的标题,而不显示内容

我已成功登录到我的应用程序中,但在主屏幕上有一个表,其中列出了某些项目,而使用selenium时,它不会加载表中的内容

硒罐:2.53
Mozilla Firefox版本:46.0

同样使用谷歌chrome浏览器,但也不起作用

当我关闭浏览器(selenium打开)并手动重新打开它时,它工作正常。但当selenium打开它并转到主页时,表数据不会加载

 <div class="project-list-bg" _ngcontent-c1="">
<div class="col s12 project-container" _ngcontent-c1="">
<main _ngcontent-c1="">
<div class="col s12 search-block" _ngcontent-c1="">
<div class="search-wrapper" _ngcontent-c1="">
<label _ngcontent-c1="">Search: </label>
<div class="card" _ngcontent-c1="">
<input class="ng-untouched ng-pristine ng-valid" type="text" _ngcontent-c1="" name="search">
</div>
</div>
</div>
<table id="myTable" class="bordered centered " _ngcontent-c1="">
<thead _ngcontent-c1="">
<tr _ngcontent-c1="">
<th class="grey-text text-darken-1" width="10%" _ngcontent-c1="">
Project ID
<i class="material-icons" _ngcontent-c1="">keyboard_arrow_down</i>
</th>
<th class="grey-text text-darken-1" width="17%" _ngcontent-c1="">
Project Name
<i class="material-icons" _ngcontent-c1="">keyboard_arrow_down</i>
</th>
<th class="grey-text text-darken-1" _ngcontent-c1="" style="width: 12%;">
Date Completed
<i class="material-icons" _ngcontent-c1="">keyboard_arrow_down</i>
</th>
<th class="grey-text text-darken-1" width="10%" _ngcontent-c1="" style="background-image: none; ">
# of Runs
<i class="material-icons" _ngcontent-c1="">keyboard_arrow_down</i>
</th>
<th class="grey-text text-darken-1" width="10%" _ngcontent-c1="" style="background-image: none; ">
Status
<i class="material-icons" _ngcontent-c1="">keyboard_arrow_down</i>
</th>
<th class="grey-text text-darken-1" width="16%" _ngcontent-c1="" style="background-image: none; ">
Project Description
<i class="material-icons" _ngcontent-c1="">keyboard_arrow_down</i>
</th>
<th width="12%" _ngcontent-c1="" style="background-image: none; "></th>
</tr>
</thead>
<tbody _ngcontent-c1="">
</table>
<div class="pagination right-align" _ngcontent-c1="">
<pagination-controls _ngcontent-c1="">
<pagination-template>
<ul class="ngx-pagination" role="navigation" aria-label="Pagination">
</pagination-template>
</pagination-controls>
</div>
<div class="row" _ngcontent-c1="">
<div class="col s6 add-btn2 left-align" _ngcontent-c1="">
<a _ngcontent-c1="" routerlink="/project-information" href="/project-information">
<button class="btn next-btn p-btn" _ngcontent-c1=""> Add Project</button>
</a>
</div>
<div class="col s6 right-align" _ngcontent-c1="">
<ul id="myPager" class="pagination pager" _ngcontent-c1=""></ul>
</div>
</div>
</main>
</div>
</div>
我必须单击此
元素,但如果表格(可在注释中找到的表格的HTML)未正确加载,则此按钮向上移动,selenium无法找到此按钮,并返回空指针异常。

单击此
,文本为Add Project,由于AUT包含角度元素,您必须引导WebDriverWait使该元素可单击,并且您可以使用以下代码行:

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn next-btn p-btn'][normalize-space()='Add Project']"))).click();

请显示表的HTML并共享相关HTML。项目ID键盘\u箭头\u向下项目名称键盘\u箭头\u向下添加项目我必须单击此按钮,但如果上表加载不正确,则此按钮向上移动,selenium无法找到此按钮,作为回报,它会给出空指针异常。@Abhishek代替注释用此按钮编辑主要问题信息。这正是我之前试图做的,但没有成功。。。WebDriverWait wait=新的WebDriverWait(驱动程序,20);WebElement addprojectbutton;addprojectbutton=wait.until(ExpectedConditions.elementtobelickable(By.xpath(“html/body/app root/app home/div/div/main/div[3]/div[1]/a/button”);addprojectbutton。单击()@阿披舍克(Abhishek)
没有起作用
没有揭示出发生了什么错误。使用当前代码试用和错误堆栈更新问题trace@Abhishek这并不是我所提供的解决办法。复制粘贴准确的代码(解决方案)并更新我们(或问题)的状态。您想让我共享selenium代码或完整的HTML。?用您的实际代码编辑并更新主要问题
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn next-btn p-btn'][normalize-space()='Add Project']"))).click();