首页 > 解决方案 > 在 Click Button 的机器人框架上找不到定位器

问题描述

我想使用以下关键字在 RIDE 上通过机器人框架单击“创建帐户”按钮

  1. 单击按钮 id=SubmitCreate
  2. Click Button class=btn btn-default button button-medium 独占
  3. 单击按钮 xpath=//*[@id="SubmitCreate"]

在控制台上找不到上面的定位器错误正在显示。

网站链接

http://automationpractice.com/index.php?controller=authentication&back=my-account

注意:相同的脚本也适用于 Google Chrome 浏览器。它不适用于 Firefox 浏览器(版本:59.0.3)。

标签详情:

<button class="btn btn-default button button-medium exclusive" type="submit" id="SubmitCreate" name="SubmitCreate">
							<span>
								<i class="icon-user left"></i>
								Create an account
							</span>
						</button>

能否请您提供解决方案。在此先感谢。

标签: seleniumselenium-webdriverrobotframework

解决方案


试试这个 xpath

//button[@class='btn btn-default button button-medium exclusive']//following::span[1]

也试试这个 xpath

 //button[@type='submit' and @name='SubmitCreate']

像这样

driver.findElement(By.xpath("//button[@class='btn btn-default button button-medium exclusive']//following::span[1]")).click();

完整的代码是这样的:

// 打开浏览器

System.setProperty("webdriver.gecko.driver", "C:/Users/sankalp.gupta/Desktop/JAVASELN/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("file:///C:/Sankalp/test.html");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//button[@type='submit' and @name='SubmitCreate']")).click();

推荐阅读