2016-06-22 8 views
0

私はあなたがこれを解決するには私を助けてもらえwww.sears.comに機能サインインを自動化しようとしているが、以下のコードにコントロールは、Selenium WebDriverを使用してSignInフォーム内で認識しませんか?

package com.bigbasket.framework.lab; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.interactions.Actions; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 

public class Sears { 

    public static void main(String[] args) { 
     WebDriver browser = new FirefoxDriver(); 
     browser.get("http://www.sears.com/en_us.html"); 
     browser.manage().window().maximize(); 
     browser.findElement(By.xpath("//*[@id='gnf_01_tree_item_5']/span/a")).click(); 
     WebElement currentElement = browser.findElement(By.xpath("//*[@id='myProfiles']/div")); 
     Actions actions = new Actions(browser); 
     actions.moveToElement(currentElement).build().perform(); 
     browser.findElement(By.xpath("//*[@id='subnavDD_myProfile']/ul/li[1]/p/a")).click(); 

     try{ 
      WebElement formElement = browser.findElement(By.id("loginFormDisplay")); 
      currentElement = formElement.findElement(By.xpath("//*[@id='email']")); 
     }catch(Exception e){ 
      System.out.println(e.getMessage()); 
     } 
     WebDriverWait wait = new WebDriverWait(browser, 30); 
     wait.until(ExpectedConditions.visibilityOf(currentElement)); 
     currentElement.sendKeys("[email protected]"); 
     browser.quit(); 

    } 

} 

を使用して電子メールのテキストフィールドを認識できませんでしたか?私は愚かな質問をするためにSelenium WebDriverのアマチュアです。

+0

あなたはこのコードを実行しているからだエラーメッセージは何か? –

+0

@YuZhangこのような要素は例外ではありません。 –

+0

どこですか?どの行? –

答えて

0

メールフィールドはそうあなたが最初のフレームに切り替える必要があり、それをアクセスするために、iframe内にある、次はあなたの問題のための作業コードです:

 WebDriver browser = new FirefoxDriver(); 
     browser.get("http://www.sears.com/en_us.html"); 
     browser.findElement(By.xpath("//*[@id='gnf_01_tree_item_5']/span/a")).click(); 
     WebElement currentElement = browser.findElement(By.xpath("//*[@id='myProfiles']/div")); 

     Actions actions = new Actions(browser); 
     actions.moveToElement(currentElement).build().perform(); 

     WebDriverWait wait = new WebDriverWait(browser, 10); 
     wait.until(ExpectedConditions.visibilityOf(browser.findElement(By.xpath(".//*[@id='subnavDD_myProfile']/ul/li[1]/p/a")))); 
     browser.findElement(By.xpath(".//*[@id='subnavDD_myProfile']/ul/li[1]/p/a")).click(); 

     try{ 
      WebElement frameElement = browser.findElement(By.xpath(".//iframe[contains(@name, 'easyXDM_default')]")); 
      browser.switchTo().frame(frameElement); 
     } 
     catch(Exception e){ 
      System.out.println(e.getMessage()); 
     } 
     browser.findElement(By.name("email")).sendKeys("[email protected]"); 
     browser.quit(); 
+0

Ravikar:ページソースで見たフレームがたくさんあり、これがpagesourceの下のどこかにあるので、これは私が使用する必要があるフレームであることを、どうやって知りましたか?あなたは助けてもらえますか? –

+1

要素を調べるときには、フィールドがいずれかの