2017-10-09 5 views
0

私はここで問題があります。私は同じ "id"のドロップダウンボックスを自動化しようとしています。 3つのドロップダウンボックスがあります。それぞれの下で1つのオプションを選択する必要があります。助けて ? ウェブサイト:http://bookboon.com/en/basics-of-accounting-information-processing-ebook#download同じ "id"のドロップダウンボックスの妥当性確認

package flow; 

import java.util.List; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 
public class bookboon { 
    static WebDriver d ; 
    public static void main(String[] args) { 
     System.setProperty("webdriver.chrome.driver", "C:\\Users\\User_2\\Downloads\\chromedriver_win32\\chromedriver.exe"); 
     d = new ChromeDriver(); 
     d.get("http://bookboon.com/en/accounting-ebooks"); 
     List<WebElement> downlinks = d.findElements(By.className("pdf")); 
     for(int i=1;i<=downlinks.size();i++) { 
      downlinks.get(i).click(); 
      d.findElement(By.id("email")).sendKeys("[email protected]"); 
      d.findElement(By.id("undefined_flexselect")).sendKeys("Studying"); 
      d.findElement(By.id("undefined_flexselect")).sendKeys("Engineer/Science MSc"); 
      d.findElement(By.id("undefined_flexselect")).sendKeys("All India Institute of Medical Sciences (AIIMS), Delhi"); 
      //d.navigate().back(); 
      //downlinks = d.findElements(By.className("pdf")); 
     } 
    } 
} 

私はまたのXpathでみました。それを完了できませんでした。助けてください !

答えて

-1

はこれを試してください。..

d.findElement(By.id("email")).sendKeys("[email protected]"); 
WebElement fOne=d.findElement(By.xpath("html/body/div[1]/div/article/div/section[1]/form/div[2]/div[2]/div[1]/input")); 
fOne.sendKeys("Studying"); 
fOne.sendKeys(Keys.TAB); 
Sleeper.sleepTightInSeconds(2); 
WebElement fTwo=d.findElement(By.xpath("html/body/div[1]/div/article/div/section[1]/form/div[2]/div[2]/div[2]/input")); 
fTwo.sendKeys("Engineer/Science MSc"); 
fTwo.sendKeys(Keys.TAB); 
Sleeper.sleepTightInSeconds(2); 
WebElement fThree=d.findElement(By.xpath("html/body/div[1]/div/article/div/section[1]/form/div[2]/div[2]/div[3]/input")); 
fThree.sendKeys("All India Institute of Medical Sciences (AIIMS), Delhi"); 
fThree.sendKeys(Keys.TAB); 
+0

ありがとう、働くクール – SarathChandar

+0

それは完璧に動作していますなぜ人々は私の答えをdownvoted私は知らない –

1

「n番目の」xpath値を選択するには、次のようにします。

"(//elementType[@id='undefined_flexselect'])[n]" 

大括弧内のnは、選択するレコードの番号で置き換えます。

0

あなたは要素を識別するために、2つの特性を組み合わせることができます。

d.findElement(By.xpath(".//select[@name='answers' and @data-placeholder='Studying or working?']")).sendKeys("Studying"); 

またはそれらのすべてを取得し、その後それぞれを取る:

List<WebElement> a = driver.findElements(By.xpath(".//select[@name='answers']")); 
a.get(0).sendKeys("Studying"); 
関連する問題