2016-03-09 42 views
0

我很難讓WebDriver輸入PayPal網站的用戶名框。我已經嘗試過xpath,id,css,但是我必須在這裏丟失一些東西,因爲它應該很簡單。文本框是輸入=「電子郵件」的代碼最底部的那個文本框WebDriver Selenium:無法將用戶名插入PayPal的用戶名框

有人可以嘗試在貝寶的網站和學校我這個嗎?如果我只是使用Firebug/Firepath給出的xpath代碼,或者我使用WebElement username = driver.findElement(By.id(「email」)),那麼我沒有找到元素。

code

+0

請參閱HTML代碼的附圖。 – TomZheng

+0

你可以通過看到html發佈url,我找不出解決方案。 –

+0

嘗試使用by.name(「login_email」) –

回答

1

所以我看着HTML多一點點實現,裏面有一種形式....我能得到它,此代碼的工作:

String URL = ("https://www.paypal.com/signin/?country.x=US&locale.x=en_US"); 
    driver.get(URL); 
    WebElement form = driver.findElement(By.cssSelector(".main form")); 
    WebElement username = form.findElement(By.id("email")); 
    username.sendKeys("test"); 
1

繼C#代碼適合我。嘗試使用Java相同,應該工作。

[Test] 
    public void TestMethod() 
    { 
     IWebElement username = driver.FindElement(By.CssSelector("form[name='login'] input#email")); 
     username.SendKeys("anytext"); 
    } 
1

只是嘗試這樣的:我的機器上

WebElement email = driver.findElement(By.cssSelector("#email")); 
email.click(); 
email.clear(); 
email.sendKeys("[email protected]"); 

它的做工精細。

1

設法通過與下面的C#代碼將用戶名和密碼,然後簡單地切換到iframe來做到這一點:

driver.SwitchTo().Frame(driver.FindElement(By.TagName("iframe"))); 
var emailAddressLogin = driver.FindElement(By.Id("email")); 
       emailAddressLogin.SendKeys("EnterEmailAddress"); 
       var password = driver.FindElement(By.Id("password")); 
       password.SendKeys("EnterPassword"); 

這是使用貝寶沙箱環境。

相關問題