<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Excel To HTML using codebeautify.org</title>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Excel To HTML using codebeautify.org</title>
</head>
<body>
<md-dialog-container class="mat-dialog-container" role="dialog">
<cdk-focus-trap>
<!--template bindings={
"ng-reflect-ng-if": "true"
}-->
<div tabindex="0"></div>
<div class="cdk-focus-trap-content">
<!--template bindings={
"ng-reflect-portal": null
}-->
<app-confirmation-dialog _nghost-lok-51="">
<div _ngcontent-lok-51="" class="box-holder">
<div _ngcontent-lok-51="" class="header-row text-center-align" fxlayoutalign="space-between center" ng-reflect-klass="header-row" ng-reflect-ng-class="[object Object]" ng-reflect-align="space-between center" style="justify-content: space-between; align-items: center; align-content: center; display: flex; flex-direction: row; box-sizing: border-box; -webkit-box-align: center; -webkit-box-orient: horizontal; -webkit-box-direction: normal;">
<div _ngcontent-lok-51="" class="header-title "></div>
<div _ngcontent-lok-51="" class="close-btn">
<i _ngcontent-lok-51="" class="icon-close"></i>
</div>
</div>
<div _ngcontent-lok-51="" class="box-content">
<div _ngcontent-lok-51="" class="content-holder text-center-align" fxlayoutalign="start start" ng-reflect-klass="content-holder" ng-reflect-ng-class="[object Object]" ng-reflect-align="start start" ng-reflect-inner-h-t-m-l="Ticket no.
<a target="_blank" href="/v2/tickets/5986813"> 5986813</a> &#160; has been created and is unassigned" style="justify-content: flex-start; align-items: flex-start; align-content: flex-start; display: flex; flex-direction: row; box-sizing: border-box; -webkit-box-pack: start; -webkit-box-align: start; -webkit-box-orient: horizontal; -webkit-box-direction: normal;">Ticket no.
<a target="_blank" href="/v2/tickets/5986813"> xyz</a> has been created
</div>
<div _ngcontent-lok-51="" class="action-container" fxlayoutalign="end end" ng-reflect-align="end end" style="justify-content: flex-end; align-items: flex-end; align-content: flex-end; display: flex; flex-direction: row; box-sizing: border-box; -webkit-box-pack: end; -webkit-box-align: end; -webkit-box-orient: horizontal; -webkit-box-direction: normal;">
<!--template bindings={
"ng-reflect-ng-if": null
}-->
<button _ngcontent-lok-51="" class="od-button small action-button" style="margin-right: 0;" type="button"> Ok </button>
</div>
</div>
</div>
</app-confirmation-dialog>
</div>
<!--template bindings={
"ng-reflect-ng-if": "true"
}-->
<div tabindex="0"></div>
</cdk-focus-trap>
</md-dialog-container>
</body>
</html>
</body>
</html>
&#13;
在上面的代码片段中,我想执行以下操作 我想看看门票ID 2.单击是按钮
我尝试了多个解决方案,但收到错误消息 org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素: 我使用xpath作为 1. // a [包含(@href,&#34; / v2 / tickets /&#34;)] 2. // div [normalize-space(text())=&#39; Ticket no。&#39;] / a
请有人帮我找到解决方案
答案 0 :(得分:0)
尝试在显式等待下使用以下代码,等待元素存在:
By ticketID = By.xpath("//a[contains(@href,'/v2/tickets/')] ");
By okButton = By.cssSelector("button.od-button.small.action-button");
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(ticketID));
driver.findElement(By.xpath("//a[contains(@href,'/v2/tickets/')] ")).getText();
wait.until(ExpectedConditions.presenceOfElementLocated(okButton));
driver.findElement(By.cssSelector("button.od-button.small.action-button")).click();