2017-10-10 72 views
0

我嘗試了很多次使用不同的xpath,並在不同的論壇中詢問,但沒有得到解決方案。等待你的幫助。無法將密鑰發送到硒中的用戶名框中

package chromedriver; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class Espncom { 

    public static void main(String[] args) { 
     // TODO Auto-generated method stub 

     System.setProperty("webdriver.gecko.driver","C:\\Selenium softwares\\geckodriver-v0.19.0-win64\\geckodriver.exe"); 

     WebDriver driver= new FirefoxDriver(); 
     driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 
     driver.get("http://www.espn.com/"); 
     driver.findElement(By.linkText("Log In")).click(); 

     //driver.findElement(By.xpath("//input[@placeholder='Username or Email Address']")).sendKeys("cricket"); 
     driver.findElement(By.xpath(".//div/div/section/section/form/section/div[1]/ 
     div/label/span[2]/input")).sendKeys("cricket"); 

    } 
} 

HTML代碼的用戶名或郵箱地址:

<input placeholder="Username or Email Address" autocapitalize="none" autocomplete="on" autocorrect="off" spellcheck="false" ng-model="vm.username" ng-pattern="/^[^<&quot;>]*$/" ng-required="true" did-disable-validate="" ng-focus="vm.resetUsername()" class="ng-pristine ng-invalid ng-invalid-required ng-valid-pattern ng-touched" tabindex="0" required="required" aria-required="true" aria-invalid="true" type="email"> 
+0

在哪些論壇無法獲得幫助?出於好奇,就像Auro在簡要檢查您嘗試與之交互的頁面後提到的一樣,它包含「框架」。爲了使硒與硒相互作用,需要「切換」。 – IamBatman

回答

1

在ESPN網站上,當你點擊登錄,然後它會打開一個框架。你需要切換到框架,然後你需要嘗試找到電子郵件或名稱文本框。 嘗試使用以下代碼並更新回

driver.switchTo().frame("disneyid-iframe"); 
    driver.findElement(By.xpath("//input[@placeholder='Username or Email address']")).sendKeys("cricket"); 
+0

我用上面的代碼也是這樣。它沒有工作。 (driver.findElement(By.name(「disneyid-iframe」))); driver.findElement(By.xpath( 「//輸入[@類型= '電子郵件']」))點擊(); (「//輸入[@ type ='email']」))。sendKeys(「cricket」); – sravanthi

+0

沒有工作的意思,是否有任何你得到的錯誤,如果這樣分享我的錯誤,以便我可以幫助你。 –

+0

獲取此錯誤 線程「main」中的異常org.openqa.selenium.ElementNotInteractableException: 構建信息:版本:'3.6.0',修訂:'6fbf3ec767',時間:'2017-09-27T16:15:26.402Z 「 – sravanthi

相關問題