首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为用React.js组件开发的web应用程序实现Selenium web驱动程序

如何为用React.js组件开发的web应用程序实现Selenium web驱动程序
EN

Stack Overflow用户
提问于 2017-11-07 21:02:00
回答 1查看 783关注 0票数 0

我正在从事硒自动化的工作,我正在测试的应用程序是基于react.js技术的,它有很多动态内容。因此,我永远找不到任何元素的ID或名称。我总是要搜索包含文本的内容。此外,它还具有基于react.js的表,并且没有表、tr或td组件。

一个单元格的xpath:“//*

代码语言:javascript
复制
[@id='react']/div/div/span/span/span/div/div/div[2]/div[1]/div/div[1]/div/div/div/div[1]/div/div/div[1]". 

我总是发现类似的xpath按钮,选择下拉或任何元素。有人帮助我完成这个react.js实现吗?

很难找到动态元素并定位这些元素。此外,获得复选框状态变得不可能;选中复选框时:

代码语言:javascript
复制
<span class="MuiButtonBase-root-203 MuiIconButton-root-270 MuiSwitchBase-root-295 MuiSwitchBase-default-297 MuiCheckbox-default-292 MuiSwitchBase-checked-298 MuiCheckbox-checked-293">
<span class="MuiIconButton-label-276">
<svg class="MuiSvgIcon-root-279" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<input class="MuiSwitchBase-input-296" value="on" type="checkbox">
</span>
<span class="MuiTouchRipple-root-205"></span>

未选中复选框时:

代码语言:javascript
复制
<span class="MuiButtonBase-root-203 MuiIconButton-root-270 MuiSwitchBase-root-295 MuiSwitchBase-default-297 MuiCheckbox-default-292">
<span class="MuiIconButton-label-276">
<svg class="MuiSvgIcon-root-279" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<input class="MuiSwitchBase-input-296" value="on" type="checkbox">
</span>
<span class="MuiTouchRipple-root-205"></span>

有人有主意吗?如何读取复选框和整个表?

我有三个复选框(Text1、Text2和Text3)。Lables、Text1等是根据以前的selection..Now动态更改的,因此,我要检查复选框的状态,然后执行适当的操作

代码语言:javascript
复制
<span class="MuiButtonBase-root-461 MuiIconButton-root-528 MuiSwitchBase-root-553 MuiSwitchBase-default-555 MuiCheckbox-default-550">
<span class="MuiIconButton-label-534">
<svg class="MuiSvgIcon-root-537" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"/>
</svg>
<input class="MuiSwitchBase-input-554" value="on" type="checkbox"/>
</span>
<span class="MuiTouchRipple-root-463"/>
</span>
<p class="MuiTypography-root-1 MuiTypography-body1-10 MuiFormControlLabel-label-549">Text1</p>


<label class="MuiFormControlLabel-root-546 MuiFormControlLabel-hasLabel-548">
<span class="MuiButtonBase-root-461 MuiIconButton-root-528 MuiSwitchBase-root-553 MuiSwitchBase-default-555 MuiCheckbox-default-550">
<span class="MuiIconButton-label-534">
<svg class="MuiSvgIcon-root-537" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<input class="MuiSwitchBase-input-554" value="on" type="checkbox"/>
</span>
<span class="MuiTouchRipple-root-463"/>
</span>
<p class="MuiTypography-root-1 MuiTypography-body1-10 MuiFormControlLabel-label-549">Text2</p>


<span class="MuiButtonBase-root-461 MuiIconButton-root-528 MuiSwitchBase-root-553 MuiSwitchBase-default-555 MuiCheckbox-default-550">
<span class="MuiIconButton-label-534">
<svg class="MuiSvgIcon-root-537" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<input class="MuiSwitchBase-input-554" value="on" type="checkbox"/>
</span>
<span class="MuiTouchRipple-root-463"/>
</span>
<p class="MuiTypography-root-1 MuiTypography-body1-10 MuiFormControlLabel-label-549">Text3</p>
EN

回答 1

Stack Overflow用户

发布于 2017-11-07 21:25:12

使用Xpath-contains而不是string-contains

  • 使用//tag[contains(@attr, 'string')] (例如//spans[contains(@class, 'MuiCheckbox-checked')] )缩短xpath

代码解决方案(逐级)

  • 首先,选择高级元素。
  • 然后,找到您的二级元素(即Button)。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47167380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档