1

Selenium WebDriverを使用して、Excelファイルから読み取った文字列でWebページのドロップダウンメニュー要素を選択しようとしています:

        Xls_Reader data = new Xls_Reader("src//com//testexcel//data//data3.xlsx");
        String values = data.getCellData("DropList", "Index_Value", 2);
        String selections[] = values.split(",");

それらは次の形式になっています: 建設、エンジニアリング、法律など。

選択しようとしている各要素は次のようになります。

<div class="ui-dropdownchecklist-item ui-state-default" style="white-space: nowrap;">
<input id="ddcl-selInd-i3" class="active" type="checkbox" tabindex="0" index="3" value="11">
<label class="ui-dropdownchecklist-text" for="ddcl-selInd-i3" style="cursor: default;">Construction</label>
</div>

<div class="ui-dropdownchecklist-item ui-state-default" style="white-space: nowrap;">
<input id="ddcl-selInd-i5" class="active" type="checkbox" tabindex="0" index="5" value="03">
<label class="ui-dropdownchecklist-text" for="ddcl-selInd-i5" style="cursor: default;">Engineering</label>
</div>

コードは次のとおりです。

package com.selftechy.parameterization;

import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class JobServe {

    static WebDriver driver = new FirefoxDriver();

    public static void main(String[] args) throws InterruptedException {


        driver.get("https://www.jobserve.com/gb/en/Candidate/Home.aspx");
        driver.findElement(By.xpath(".//*[@id='ddcl-selInd']/span")).click();

        readExcelWords();


    public static void readExcelWords() {
        Xls_Reader data = new Xls_Reader("src//com//testexcel//data//data3.xlsx");
        String values = data.getCellData("DropList", "Index_Value", 2);
        String selections[] = values.split(",");

//help  
List<WebElement> iList = driver.findElements(By.xpath("//*[@id='ddcl-selInd-ddw']"));
    for (int i=0; i<selections.length; i++) {
    driver.findElement(By.xpath("//*[text()='" + selections[i] + "']")).click();

xpath が間違っていて、おそらくデータ型の操作方法が間違っていることはわかっています。配列値に基づいて xpath 選択を機能させる方法が必要です。私はJavaとSeleniumに比較的慣れていないので、助けていただければ幸いです。

4

2 に答える 2

1

試す

findElement(By.xpath("//label[.='xyz']/../input"));

xyz建設、エンジニアリングなどのいずれかです

于 2012-08-12T01:33:06.557 に答える
0

名前を使用して使用することをお勧めします

findElement(By.name("xyz"));

入力コードでname属性を使用した後。

何かのようなもの -

<div class="ui-dropdownchecklist-item ui-state-default" style="white-space: nowrap;">
<input name ="Construction" id="ddcl-selInd-i3" class="active" type="checkbox" tabindex="0" index="3"value="11">
<label class="ui-dropdownchecklist-text" for="ddcl-selInd-i3" style="cursor: default;">Construction</label>
</div>

上記のような擬似コードを使用して、このメソッドで要素を見つけることができます。

于 2012-08-11T20:01:24.680 に答える