selenium - 在 Click Button 的机器人框架上找不到定位器
问题描述
我想使用以下关键字在 RIDE 上通过机器人框架单击“创建帐户”按钮
- 单击按钮 id=SubmitCreate
- Click Button class=btn btn-default button button-medium 独占
- 单击按钮 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>
能否请您提供解决方案。在此先感谢。
解决方案
试试这个 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();
推荐阅读
- php - 如何限制用户只上传纯 html 文件
- csv - 在 Odoo 13 中导入文件 excel 失败。如何?
- vue.js - Vue PWA Precache 清单与 HTML 预取链接
- android - 来自 android-beacon-library 的 ScanJob 中的 ConcurrentModificationException
- circuit-sdk - Q: Google Function 中的client.logon 过期
- macros - Julia:宏、表达式和 Meta.parse
- php - 如何模仿原生 404 页面?
- c - 非终止函数问题(无依赖关系)
- python - Pandas - 重复行和切片字符串
- twiki - 如何列出我创建的所有主题