I have a webpage:
<div class="formfonttitle">Wireless - General</div>
<div style="margin-left:5px;margin-top:10px;margin-bottom:10px"><img src="/images/New_ui/export/line_export.png"></div>
<div class="formfontdesc">Set up the wireless related information below.</div>
<table width="99%" border="1" align="center" cellpadding="4" cellspacing="0" id="WLgeneral" class="FormTable">
<tr id="wl_unit_field">
<th>Frequency</th>
<td>
<select name="wl_unit" class="input_option" onChange="_change_wl_unit(this.value);">
<option class="content_input_fd" value="0" >2.4GHz</option>
<option class="content_input_fd" value="1" selected>5GHz</option>
</select>
</td>
</tr>
I am trying to select "2.4GHz" using xpath. By default "5GHz" option is selected. I am doing this from Python script and using selenium webdriver.
I am doing this:
elements = mydriver.find_element_by_xpath("//div[#class='wl_unit']")
title = elements[1].find_elements_by_xpath(".//div[#class='content_input_fd']")
but it's not working.
You can use the following XPath to find the 2.4GHz option element, and then peform 'click' on the element to get it selected :
option = mydriver.find_element_by_xpath("//select[#name='wl_unit']/option[#value='0']")
option.click()
You can do this by running JavaScript with selinum like this
mydriver.execute_script("$('.input_option option[value="0"]')")
This may also help you for selecting an option in python selenium.
#Manoj
It is under select, so you can use select method which is generally used for dropdown as follows:
You wrote this.
Webelement elements = mydriver.find_element_by_xpath("//div[#class='wl_unit']")
Now continue :
Select object = new Select(elements);
object.selectByValue(1);
or
object.selectByVisibleText("5GHz")
Hope this will help you..
Try Following code
WebElement wlUnit= WebElement elea= driver.findElement(By.name("wl_unit"));
Select wlSelect = new Select(wlUnit);
wlSelect.selectByValue(0);
OR
WebElement wlUnit= WebElement elea= driver.findElement(By.name("wl_unit"));
Select wlSelect = new Select(wlUnit);
wlSelect.selectByVisibleText("2.4GHz");
Related
I display 51 questions with their related answers on a page.
Both information come from one web-service call.
<tbody>
<tr *ngFor="let QuestionOption of questions; trackBy: trackQuestionById; let i = index;">
<th scope="row">{{QuestionOption.id}}</th>
<td>{{QuestionOption.name}} {{QuestionOption.description}}
</p>
<select class="form-control" name="selectAnswer" [(ngModel)]="answer[i]">
<option *ngFor="let answers of QuestionOption.Answers" [ngValue]="answers.id">{{answers.description}}</option>
</p>
</td>
</tr>
</tbody>
on the typescript code I try the following:
answer: Answer[];
this.answer = new Array<Answer>();
The type Answer has multiple fields like: Id, Name, Score, Description
What is not working is that I always have get the Id into the answer[i]
but I want to have the id in the field answer[i].id
If i change the
[(ngModel)]="answer[i]"
into
[(ngModel)]="answer[i].id"
I get the following exception:
ERROR TypeError: "_co.caaAnswer[_v.context.index] is undefined"
I also tried:
[(ngModel)]="answer[i]?.id"
So is it correct to use answer[i] ? and then in the option I should somehow assign to answer[i].id the selected value. If so somebody can help how to do it.
Any help is appreciated! Thanks a lot.
augeres
I found the solution. The problem was that the compareWith function did not work properly because of the Array. It only works in case you name the html select based upon the array index:
Working version:
<select class="form-control" id="field_answer{{i}}" name="field_answer{{i}}" [(ngModel)]="resultAnswer[i].answer" [compareWith]="compareFn">
<option [ngValue]="answer" *ngFor="let answer of Question.answers; trackBy: trackAnswerById">{{answer.id}} {{answer.description}}</option>
</select>
You have to push into answer on select change like this
<select class="form-control" name="selectAnswer" [(ngModel)]="selectedAnswerId" (change)="setAnswer(i)">
<option *ngFor="let answers of QuestionOption.Answers" [ngValue]="answers.id">{{answers.description}}</option>
<select>
in component.ts
selectedAnswerId : number;
setAnswer(index){
this.answer[index].push({id : this.selectedAnswerId})
}
I want to click on a hyperlink on a webpage using VBA that I have found using the below method:
Set trs = ie.document.getElementsByTagName("tr")
For Each trObj In trs
Set tds = trObj.getElementsByTagName("td")
For Each tdObj In tds
If tdObj.className = "btn_container" And tdObj.innerText = "Reinstate Award" Then
tdObj.Click
End If
Next
Next
I can't get the tdObj.Click bit to click the hyperlink.
The html is below:
<td class="btn_container">
<input name="_linkSubmit" type="hidden"><a name="assessment_Reinstate" class="button_link" id="assessment_Reinstate" onclick="javascript:return disableLinks(this.href);" href='javascript:submitLink(document.Form0,"assessment_Reinstate");' type="button" renderer="uk.co.slc.tapestry.link.PortalLinkRenderer#1a79ffb">Reinstate Award</a>
</td>
Any help would be greatly appreciated.
Thanks
Jim
You can try using the link id
ie.document.querySelector("#assessment_Reinstate").click
I am trying to create xpath this (Unscheduled Visitor Check-In) button. i am unable to find the button name or id. can anyone help me out from this issue please. will appreciate that. please see the attachment.
<div id="SAFEControl307369" class="buttontextactivestyle" uniquefieldid="307369" onselectstart="return false" onchange="setAttribute('IsModified','1');" onclick=" document.body.style.cursor = 'wait'; window.location.href = 'QSForm.aspx?FormID=194&Hidden=1';return false;" datatype="" boundcolumn="" ismodified="0" style="position:absolute;left:280px;top:5px;height:0px;width:250px; ;" caption="" tabindex="-1">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr style="height:20px;cursor:pointer;">
<td class="buttonleftactivestyle"/>
<td class="buttonmiddleactivestyle" align="center">
<div>Unscheduled Visitor Check-In</div>
[Screenshot of the application with xpath][1]
IWebElement element = driver.FindElement(By.XPath("//div[#id='SAFEControl307369']/table/tbody/div"));
When you checking the element you need look on the try for create the XPath.
Please use below xpath:
//div[contains(.,'Unscheduled Visitor Check-In')]
You can try the code below:
WebElement element= driver.findElement(By.xpath("Your XPath"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Feel free to change the locator in the code above. Try to with xpath provided by the firepath as shown in image.
So I am creating 2 drop down menus, the 2nd of which dynamically changes based off the first. However, the 2nd menu does not render the change, but is providing the correct options when viewing the Post with Firebug.
Here is the function that is supposed to render the menu
def findSubtagsForTags(){
print Tag.getAll()
def tag = Tag.get(params.tag.id)
render(template: 'subtagSelection', model: [subtags: tag.subtags])
}
This method is being called in my _form.gsp template, which is called by create.gsp (both generated by grails scaffolding for the most part). Here is my code snippet where I am calling it
<g:select name="tag.id" from="${Tag.list()}" optionKey="id" optionValue="tagName"
noSelection="['':'Choose Tag']"
onchange="${remoteFunction (
controller: 'tag',
action: 'findSubtagsForTags',
params: '\'tag.id=\' + this.value',
update: 'subtagSelection'
)}" />
<td id="subtagSelection" valign="top">
<select>
<option>Choose Tag</option>
<g:select name="subtags.id" id="subtags.id" from="${[]}" optionKey="id"/>
</select>
</td>
and the subtagSelection template that is being rendered is
<g:select name="subtag.id" from="${subtags}" optionValue="name" optionKey="id" id = "subtags.id"/>
The 2nd menu on the page is always "CHoose Tag", but using Firebug, when I look at the post, this is generated
<select name="subtag.id" id="subtags.id" >
<option value="1" >Training</option>
<option value="2" >Software</option>
</select>
however, there is no change to the 2nd menu.
Under the Net Tab of firebug, This is the 'put' request called by my function
Post:
Parameters : tag.id 1
Source:
tag.id=1
Response:
<select name="subtagSelection" id="subtagSelection" >
<option value="1" >Training</option>
<option value="2" >Software</option>
</select>
Any ideas/solutions?
EDIT: Issue was resolved after changing my code around a little, using https://stackoverflow.com/a/3771240/3691484 as a reference, changing the template file among other things
Try a few modifications - see if makes any difference:
<g:select name="tag.id" from="${Tag.list()}" optionKey="id" optionValue="tagName"
noSelection="['':'Choose Tag']"
onchange="${remoteFunction (
controller: 'tag',
action: 'findSubtagsForTags',
params: "'tag.id=' + this.value",
update: 'subtagSelection'
)}"
/>
<td id="subtagSelection11" valign="top">
<div id="subtagSelection">
<g:select name="subtags.id" id="subtags.id" from="[]"
optionKey="id" noSelection="['': 'Choose Tag']" />
</div>
</td>
There was a minor issue a select within a select? - use the noSelection tag for when nothing is selected
I have a sql statement that pulls infomration about tagnum's for individual pidm's. Every pidm can have multiple tagnum's so I am dropping the information into an arraylist. I want to display the contents of this arraylist in a dropdown box on a html page.
Here is the code for the arraylist:
<table style="border:transparent" style="width:100%">
<tr>
<td style ="width: 300px;">
<select style="width:150px;"tabindex="5" name="Tag">
<option></option>
<%} rscheck.close();
ResultSet rsTagCheck = stmt.executeQuery("SELECT PARKING.XKRPRMT.XKRPRMT_PIDM, PARKING.XKRPRMT.XKRPRMT_STATUS, PARKING.XKRPRMT.XKRPRMT_EXPIRE_YR, PARKING.XKRPRMT.XKRPRMT_TAG FROM PARKING.XKRPRMT WHERE XKRPRMT_PIDM ='" + BannerID + "'");
while (rsTagCheck.next()){
ArrayList<String> myTag = new ArrayList<String>();
myTag.add(rsTagCheck.getString("XKRPRMT_TAG"));
%>
<option><%= myTag.get(0) %></option>
</select>
</td>
I can get the first element to show in the drop down box, but anything after that show an outofbounds exception. I want to know how to display ALL of the information in the arraylist.
#Pointy I did that and all I got was this:
It put the first one in there, but the rest would not populate!!
There's no reason to create the array list at all.
while (rsTagCheck.next()) {
%>
<option><%= rsTagCheck.getString("XKRPRMT_TAG") %></option>
<%
}
edit — of course in practice you should be careful about what those strings might contain. If the strings come from some sort of user input, you shouldn't be just dumping them unwashed into the HTML. That's a whole other subject however.
Don't use scriptlets, use jstl tags and in this case
<c:forEach var="myTag" items="${rsTagCheck}">
and
<c:out value="${myTag.getString('XKRPRMT_TAG')}" />
Actually looking again at your code, I would not put the db query in a scriptlet! DB access should not be done here, pass the resultsets to jsp from servlet, and loop through data using jstl.