java - 按可用 ID 单击元素
问题描述
我有一个奇怪的情况,其中 Angular 元素使用 2 个随机 ID 呈现 html:
WebDriverWait webDriverWait = new WebDriverWait(driver, 5);
System.out.println("Click on Sub Tab " + title_id + " using id locator " + tab_id);
WebElement webElement = webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("mat-tab-label-5-0")));
webElement.click();
或者
WebDriverWait webDriverWait = new WebDriverWait(driver, 5);
System.out.println("Click on Sub Tab " + title_id + " using id locator " + tab_id);
WebElement webElement = webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("mat-tab-label-3-0")));
webElement.click();
顺序是随机的,我需要一些方法来点击可用的 id。有什么方法可以结合,例如:
By.id("mat-tab-label-3-0" OR "mat-tab-label-5-0")
有什么解决办法吗?
解决方案
您可以切换到 CSS 选择器。
ExpectedConditions.elementToBeClickable(By.cssSelector("#mat-tab-label-3-0,#mat-tab-label-5-0"))
#
表示 ID 并,
表示 OR。
推荐阅读
- java - 如何在一个类中创建对象并将它们保存在另一个类中的数组中?
- javascript - 拿来。处理来自服务器的 500 个响应
- c++ - 如何检索指向在单独线程上运行的函数的移动指针?
- loops - 在 netlogo 中循环以创建多个属性
- css - CSS 属性“调整大小”不适用于“粘性”
- reactjs - 如何更新道具依赖状态
- java - onItemSelected Listner 不会被数据库中的长字符串数组触发
- javascript - Javascript页内滚动偏移
- javascript - how to make links working like real in history API?
- android - Is it possible to Fetch the Data from this "Users" Object to this layout?