如何在c#中使用Selenium在带有aria hidden="true"的元素上发送密钥



我的代码如下

第一部分代码

第二部分代码

我尝试代码

driver.FindElement(By.XPath("//*[@id='idms-input-labelledby-1601454890596-1']")).SendKeys("");

但我发现有一个错误,因为每次 id都会更改

非常感谢

id确实在不断变化,但你必须找到保持不变的。。。

你的答案可能是:

driver.FindElement(By.XPath("//div[@class='form-element']/input[contains(@class,'generic-input-field   form-textbox form-textbox-text')]")).SendKeys("urfirstname");

我试过了,效果很好。

您可以通过访问它们的索引来获取它们并发送密钥。

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
List<WebElement> elements = wait.until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.XPath("//idms-error-wrapper/div/div/input")));
elements.get(0).SendKeys("");

最新更新