通过硒选择一个JavaScript下拉列表? [英] Selecting a javascript drop down via selenium?

查看:89
本文介绍了通过硒选择一个JavaScript下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我要通过Selenium Webdriver选择所有恢复"选项的javascript下拉列表:

Below is the javascript drop down from which I want to select the "All Resume" option via selenium webdriver:

<div id="resume_freshness_container">
<div class="dropdown_small_wrapper">
<div class="left">Last 6 Months</div>
                                <div class="right"><img class="clip_image" src="http://media.monsterindia.com/v2/recruiter/2.1/new_search/newlook_combined.png"></div>
                                <div class="clear_both"></div>
                                </div></div>
<script language="javascript">  
                jQuery(document).ready(function(){  createSingleSelectCombo({id:'selDay',valueVariableName:'day',tabindex:'62',label:"",preSelected:"180",replaceWithId:'resume_freshness_container',width:'216',heightOptions:'height:240px;overflow-y:auto',animateScroll:true,
                options:[{id:'1',values:"in last 1 day"},
                {id:'3',values:"in last 3 days"},               
                {id:'7',values:"in last 7 days"},               
                {id:'15',values:"in last 15 days"},             
                {id:'30',values:"in last 1 month"},             
                {id:'90',values:"in last 3 months"},                
                {id:'180',values:"in last 6 months"},               
                {id:'360',values:"in last 12 months"},              
                {id:'540',values:"in last 18 months"},
                {id:'9999',values:"All Resumes"},
                {id:'4-7',values:"4-7 days"},
                {id:'8-15',values:"8-15 days"},
                {id:'16-30',values:"16-30 days"},
                {id:'31-90',values:"1-3 months"},
                {id:'91-180',values:"3-6 months"},
                {id:'181-360',values:"6-12 months"},
                {id:'361-540',values:"12-18 months"},
                {id:'541-9999',values:"Only older than 18 months"}

                ]});


                borderTopSingleSelect({container:'resume_freshness_container',afterId:'10'});

            });


</script>   

我已使用以下代码选择下拉菜单,然后选择所需的选项:

I have used the following code to select the dropdown and then select the required option:

Select select = new Select(driver.findElement(By.id("resume_freshness_container")));
select.deselectAll();
select.selectByVisibleText("All Resumes");

我也尝试过使用id"selDay"选择它,但两次都给了我下面列出的相同例外

Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"

*我是硒新手,请帮助我知道我要去哪里错了*

*I am new to selenium so kindly help me out to know where I am going wrong *

推荐答案

是的,您不能使用Select类来实现它-它专门用于select->option HTML结构.

Yeah, you cannot approach it with Select class - it is specifically for select->option HTML structures.

您首先需要使用id="selDay"找到元素,单击它,然后使用所有简历"文本找到该元素,然后单击它:

You need to first locate the element with id="selDay", click on it, locate the element with "All Resumes" text and click on it:

WebElement selDay = driver.findElement(By.id("selDay"));
selDay.click();

WebElement allResumes = selDay.findElement(By.xpath("//*[.=\"All Resumes\"]"));
allResumes.click();

这篇关于通过硒选择一个JavaScript下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆