0

我使用哪個發送@在硒中輸入的正確方法?

email.SendKeys("[email protected]") 

但有時是把myemail2gmail.com,穿着2代替@,我已經做了一個快速研究,我想知道這是不是最好的解決辦法

email.SendKeys("myemail" + Keys.Shift + "2" + Keys.Shift + "gmail.com"); 

問題出在IE 11中,我正在使用Visual Studio c#中的specflow的瀏覽器。

回答

-1

我用比@Agent肩類似的東西說

var _element= driver.FindElement(By.Id("id")); 
IJavaScriptExecutor js = (IJavaScriptExecutor)driver; 
js.ExecuteScript("arguments[0].setAttribute('value', '[email protected]')", _element); 
0

我聽說過人們在IE和Edge瀏覽器中遇到了與特殊字符結合的sendkeys問題。事實上,爲了做到這一點,正確的做法是:

email.SendKeys("[email protected]") 

如果不工作,你可以嘗試使用JavaScript作爲一種變通方法輸入電子郵件地址進入該領域。事情是這樣的:

IWebElement email = driver.FindElement(By.Id("email")); 

IJavaScriptExecutor js = driver as IJavaScriptExecutor; 
string script = "arguments[0].setAttribute('value', 'arguments[1]');"; 
js.ExecuteScript(script, email, "[email protected]"); 
+0

此代碼是不是在元素添加電子郵件 – Marion

相關問題