我需要知道在單擊來自選擇輸入的選項時如何檢查頁面中的更改。這是選擇輸入:如何檢查使用硒進行選擇更改時插入哪個字段
<select onchange="showCategory('category', 'carextras', 'company_ad', 'err_category');suggestCategory(document.formular.subject.value, this.value, 'subject-warning');" name="category" id="category">
點擊一個選項,JavaScript將創建不同的輸入類型(文本,選擇和其他)在用戶點擊的功能。我需要知道如何獲取哪些輸入插入到頁面中。有人能幫我嗎?有人可以給我一個建議嗎?謝謝!!! :)
解決的(壞的方式),這要歸功於JacekM,以這樣的方式
WebElement cat =(new WebDriverWait(d, 1))
.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.id("categoria"));
}});
Select allCategory = new Select(cat);
File f = new File("ebay1.txt");
PrintWriter pw = new PrintWriter(f);
pw.write("Categoria\n\t\tSottocategoria\n\t\t\t\tCampi\n");
List<WebElement> categorie = allCategory.getOptions();
for(int i=1;i<3;i++){
pw.append(categorie.get(i).getText()+"\n");
categorie.get(i).click();
WebElement subcat =(new WebDriverWait(d, 1))
.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.id("sottocategoria"));
}});
Select allSubCategory = new Select(subcat);
List<WebElement> sottocategorie = allSubCategory.getOptions();
sottocategorie.get(0).click();
for(int j=1;j<sottocategorie.size();j++){
List<WebElement> before = d.findElements(By.tagName("input"));
List<WebElement> before_select = d.findElements(By.tagName("select"));
List<WebElement> before_textarea = d.findElements(By.tagName("textarea"));
List<String> before_inv = new ArrayList<String>();
List<String> after_inv = new ArrayList<String>();
for(WebElement bef : before){
if(bef.isDisplayed()){
String id = bef.getAttribute("id");
List<WebElement> labels = d.findElements(By.tagName("label"));
for(WebElement lab : labels){
if(lab.getAttribute("for").equals(id)){
before_inv.add(lab.getText());
}
}
}
}
for(WebElement bef : before_select){
if(bef.isDisplayed()){
String id = bef.getAttribute("id");
List<WebElement> labels = d.findElements(By.tagName("label"));
for(WebElement lab : labels){
if(lab.getAttribute("for").equals(id)){
before_inv.add(lab.getText());
}
}
}
}
for(WebElement bef : before_textarea){
if(bef.isDisplayed()){
String id = bef.getAttribute("id");
List<WebElement> labels = d.findElements(By.tagName("label"));
for(WebElement lab : labels){
if(lab.getAttribute("for").equals(id)){
before_inv.add(lab.getText());
}
}
}
}
sottocategorie.get(j).click();
pw.append("\t\t"+sottocategorie.get(j).getText()+"\n");
List<WebElement> after = d.findElements(By.tagName("input"));
List<WebElement> after_select = d.findElements(By.tagName("select"));
List<WebElement> after_textarea = d.findElements(By.tagName("textarea"));
for(WebElement aft : after){
if(aft.isDisplayed()){
String id = aft.getAttribute("id");
List<WebElement> labels = d.findElements(By.tagName("label"));
for(WebElement lab : labels){
if(lab.getAttribute("for").equals(id)){
after_inv.add(lab.getText());
}
}
}
}
for(WebElement aft : after_select){
if(aft.isDisplayed()){
String id = aft.getAttribute("id");
List<WebElement> labels = d.findElements(By.tagName("label"));
for(WebElement lab : labels){
if(lab.getAttribute("for").equals(id)){
after_inv.add(lab.getText());
}
}
}
}
for(WebElement aft : after_textarea){
if(aft.isDisplayed()){
String id = aft.getAttribute("id");
List<WebElement> labels = d.findElements(By.tagName("label"));
for(WebElement lab : labels){
if(lab.getAttribute("for").equals(id)){
after_inv.add(lab.getText());
}
}
}
}
List<String> finale = new ArrayList<String>();
for(String fin : after_inv){
if(!before_inv.contains(fin)){
finale.add(fin);
}
}
for(String fin:finale){
pw.append("\t\t\t\t"+fin.replace(":", "")+"\n");
}
sottocategorie.get(0).click();
}
}
pw.close();
輸入類型(文本,選擇和其他)的id是否與它們相關聯? –
不,如果你想看到的頁面是:https://annunci.ebay.it/pubblica-annuncio – JackTurky
嗯..我不認爲有一種方式,你可以檢查這個沒有任何標識符的元素。最多可以查找相應的標籤(例如輪胎)並檢查是否有對應的選擇框。這樣你就相對於該標籤 –