我打算在以下網站上自動化一個簡單的表單填充 Junit 測驗:https : //newdesign.millionandup.com
我嘗試向其發送密鑰的輸入文本欄位用 id=email 標識,我嘗試了以下兩種方法: 1.
WebElement passInput = driver3.findElements(By.className("sidebar__item-text")).get(0); // this xPath does the trick
wait.until(ExpectedConditions.visibilityOfElementLocated(emailLocator));
passInput.click();
passInput.sendKeys("emailID");
Thread.sleep(3000); // only to see the result
WebElement em1 = driver3.findElement(emailLocator);
JavascriptExecutor jse = (JavascriptExecutor)driver3;
//driver3.findElement(emailLocator).sendKeys(emString);
Thread.sleep(1000);
jse.executeScript("arguments[0].click()", em1);
jse.executeScript("arguments[0].value='[email protected]';", em1);
if (em1.isSelected()) {
System.out.println("email typed");
} else {
System.out.println("unable to send keys, element not interactable");
}
在這兩種情況下都無濟于事,文本欄位仍然不可互動,我無法將資料輸入其中。
編輯:正如評論中所建議的,我嘗試了第三種方式:
3.
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='email']")));
System.out.println("email input located");
element.click();
System.out.println("email input clicked");
element.sendKeys(emString);
元素實際上已定位,但是,一旦呼叫方法 click() 或 sendKeys() ,就會在宣告“元素不可互動”后停止執行
uj5u.com熱心網友回復:
xpath -//input[@id='email']匹配 DOM 中的 9 個元素。找到獨特的定位器很重要 -參考鏈接
滑鼠移動時會打開 Register 的彈出視窗。滑鼠移動后,將能夠查看彈出元素并與之互動。
在 xpath 下面使用將鍵發送到元素Email Address,它對我有用。
//form[@id='frmLeadModal']//input[@id='email']
像下面這樣嘗試一次,它也可能對你有用。
driver.get("https://newdesign.millionandup.com/#initial");
WebDriverWait wait = new WebDriverWait(driver, 30);
Actions actions = new Actions(driver);
actions.moveByOffset(100, 100).perform();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//form[@id='frmLeadModal']//input[@id='email']"))).sendKeys("[email protected]");
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/355818.html
上一篇:什么是Backtrace:Ordinal0[0x00723AB3 2505395]instacktraceerror在使用Selenium和ChromeDriver時意味著什么
