无法使用Selenium WebDriver单击两个继续跨度按钮



我尝试使用以下HTML代码单击两个按钮

1。

 <span translate="Resources.AddOns.TravelInsurance.Button_ContinueBooking" class="ng-scope">Continue Booking</span>
 The Xpath = //*[@id="cont_to_ins"]/span
  1. <button wn-validation-dom="prepaidcards-details" class="orange-btn btn btn-sm bold ng-scope" ng-if="!areOtherAddOnsAfterPrepaidCardsIndexAvailableInAccordion()" id="cont_to_ins" ng-click="continueBooking()"><span translate="Resources.AddOns.PrepaidCards.Button_ContinueBooking" class="ng-scope">Continue Booking</span> <i class="material-icons "></i></button>

xpath =

//*[@id="cont_to_ins"]

我尝试了多个代码,但是获取无法单击按钮的错误。

请协助使用代码以找到此元素,然后单击以移至下一页

driver.findElement(By.xpath("//span[contains(text(), 'Continue Booking')])[1]/following::button[1]")).click();
   log.debug("Click Continue ");


WebElement elementa=  driver.findElement(By.xpath("//span[text()='Continue Booking']/"));   
    JavascriptExecutor executore = (JavascriptExecutor) driver;
    executore.executeScript("arguments[0].click();", elementa);

org.openqa.selenium.invalidselectorexception:无效的选择器:无法 要找到具有XPath表达式的元素//span [包含(text((,, "继续预订"((([1]/wast :: button [1] 错误:SyntaxError:无法在"文档"上执行"评估": 字符串'//span [包含(text((,'继续 预订'(]([1]/paster :: button [1]'不是有效的XPath表达式。 (会话信息:Chrome = 74.0.3729.157((驱动程序信息: Chromedriver = 74.0.3729.6 (255758ECCF3D244491B8A1317A7A76E76E1CE10D57E9-REFS/BRANCH-HEADS/3729@{#29}(,Platform = Windows = Windows NT 10.0.17763 X86_64((警告:服务器未提供任何 stacktrace信息(命令持续时间或超时:0毫秒 有关此错误的文档,请访问: https://www.seleniumhq.org/exceptions/invalid_selector_exception.html 构建信息:版本:"未知",修订:"未知",时间:'未知' 系统信息:主机:'WN-HQ-LT-DEV-42',IP:'10 .10.11.250',OS.NAME: 'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version: '1.8.0_211'驱动程序信息:org.openqa.selenium.chrome.chromedriver 功能{acceptinsecurecerts:false,campectslcerts:false, ApplicationCacheenabled:false,browserconnectionenabled:false, 浏览名称:Chrome,Chrome:{Chromedriverversion:74.0.3729.6 (255758ECCF3D24 ...,USERDADADIR:C: USER ADEYIN〜1.ALA APPDA ...}, CSSSELECTORSENABLED:TRUE,DATABASEENABLED:FALSE,GOOG:Chromeoptions: {debuggeraddress:localhost:64341},handlesalerts:true, HastouchScreen:false,JavaScriptEnabled:True, location -contextEnabled:true,mobilemulationEnabled:false, 本地Events:True,NetworkConnectionEnabled:false,pageloadstrategy: 普通,平台:XP,平台名称:XP,Proxy:proxy((,旋转: false,setWindowRect:true,stricterfile互操作性:false, takesheapsnapshot:true,takesscreenshot:true,超时:{隐式: 0,pageload:300000,脚本:30000},出乎意料的alertbehaviour:忽略, 未经手的行为:忽略,版本:74.0.3729.157, WebStorageNabled:true}会话ID:AEBE53B2F0CE483DB0ACF2034848ECD9 ***元素信息:{使用= xpath,value =//span [contains(text((,'contine预订'(([1]/caster :: button [1]}

使用 WebdriverWait处理动态元素,然后遵循Xpath

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath('//button[@id="cont_to_ins"]/span[contains(.,"Continue Booking")]')));
element.click()

您尚未书写适当的xpath

driver.findelement(by.xpath(" ((//span [contains(text((,'contine预订'(]([1]/laste :: button [1]"(( .click((; log.debug("单击继续"(;

相关内容

最新更新