[英]Selenium Automation: How to find element to send text
I would like to automate a test in Microsoft Redeem Code page我想在 Microsoft Redeem Code 页面中自动执行测试
https://account.microsoft.com/billing/redeem https://account.microsoft.com/billing/redeem
I tried to enter value by below code:我试图通过以下代码输入值:
driver.findElement(By.id("tokenString")).sendKeys("GXXFV-CPMKR-VQVFV-2CCFD-J47GZ");
Inspect element showing:检查元素显示:
<input aria-label="Enter 25-character code" name="tokenString" type="text" autocomplete="off" spellcheck="true" placeholder="Enter 25-character code" maxlength="tokenLength" autofocus="" autocorrect="off" autocapitalize="off" id="tokenString" class="ember-text-field ember-view">
I tried lot of ways nothing worked out, Spent 4 hrs cant figure out please correct my code Environment:我尝试了很多方法都没有解决,花了 4 小时无法弄清楚请更正我的代码环境:
Eclipse IDE - Java - Selenium latest Eclipse IDE - Java - Selenium 最新
Mac OS - Chrome Mac 操作系统 - Chrome
Correct Code to find element.更正代码以查找元素。
The desired element is a Ember.js enabled element, so to click()
on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies :所需的元素是启用了Ember.js的元素,因此要在元素上
click()
,您需要为elementToBeClickable()引入WebDriverWait并且您可以使用以下任一定位器策略:
cssSelector : CSS选择器:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.ember-text-field.ember-view#tokenString[name='tokenString']"))).sendKeys("GXXFV-CPMKR-VQVFV-2CCFD-J47GZ");
xpath : xpath :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='ember-text-field ember-view' and @id='tokenString'][@name='tokenString']"))).sendKeys("GXXFV-CPMKR-VQVFV-2CCFD-J47GZ");
Checkout the following line of code:检查以下代码行:
cssSelector : CSS选择器:
new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.ember-text-field.ember-view#tokenString[name='tokenString']"))).sendKeys("GXXFV-CPMKR-VQVFV-2CCFD-J47GZ");
xpath : xpath :
new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='ember-text-field ember-view' and @id='tokenString'][@name='tokenString']"))).sendKeys("GXXFV-CPMKR-VQVFV-2CCFD-J47GZ");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.