我需要知道单击选择输入中的选项时如何检查页面中的哪些更改。这是选择输入:
<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();