Java Selenium Webdriver表达式查找以ccs开头和结尾的ccs动态元素 [英] Java Selenium webdriver expression finding dynamic element by ccs that starts with and ends with

查看:60
本文介绍了Java Selenium Webdriver表达式查找以ccs开头和结尾的ccs动态元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下需要查找的HTML元素.现在,将这个"id"添加到名称以int"0"表示的方式是动态的.最后会改变,但我知道会是什么."0--0"中的第一个int也会发生变化,但这无关紧要.

I have the below HTML element that I need to find. Now, this "id" name is dynamic in the way that the int "0" at the end will change, but I know what it will be. The first int in "0-0" will also change, but it doesn't matter what it will be.

<div id="ui-select-choices-row-0-0">

我尝试了以下代码,查找以#ui-select-choices-row-"开头的元素.并以所需的"int"输入结尾,但未按预期找到它.关于我在这里做错什么的任何建议吗?

I've tried the below code that looks for an element that starts with "#ui-select-choices-row-" and ends with the desired input of "int", but it's not finding it as expected. Any suggestions on what I'm doing wrong here?

尝试1:

driver.findElement(By.cssSelector("div[id^='#ui-select-choices-row-'] and div[id$='"+int+" div']"));

尝试2:

driver.findElement(By.cssSelector("div[id^='ui-select-choices-row-'] and div[id$='"+int+"']"));

推荐答案

您已经足够亲密.您需要从 id 的开头删除 # ,因为 # 本身表示 id 属性.

You were close enough. You need to remove the # from the beginning of the id as # itself denotes the id attribute.

要仅考虑 href data-drupal-link-system-path 属性的静态部分,可以在

这篇关于Java Selenium Webdriver表达式查找以ccs开头和结尾的ccs动态元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆