I have below html code snippet for radio button .
<label for="exceptionTrue">
<span/>
<span class="check" style="background: #F3565D;"/>
<span class="box"/>
Yes
</label>
HTML displayed is the same if the radio button is selected or if not selected in the page.
Element is in span class='check' if the radio button is selected and is in span class='box if not selected.
Since the html code is present in page if the radio button is selected or not selected.So i cannot user verifying if class='check' .
.Any idea how i can verify this...I have tried is.Selected and it doesn't work
Well I don't see a problem here, you know how this radio button works and you just need to implement this verification. Find your radio button element and than:
if (element.getAttribute("class").equals("check")){
return true; }
else {
return false; }
This is just an example, you can adjust this to your code.
EDIT: When I read your question again it's really unclear so I'm not sure if this helps. You need to provide more details on this.
Related
I am using Java and chromedriver. So far I used the following code to simply click on a button, then a small window popped up and I clicked another button. Interestingly I had not to change to any frame. All worked fine. Here is the code:
// click on button
driver.findElement(By.xpath(hyperlink_take_order)).click();
// a second small window popped up and I clicked another button
driver.findElement(By.xpath("//a[contains(text(),'accept')]")).click();
So far I used xpath to identify the buttons I need to click.
From time to time there is an additional checkbox (sometimes multiple checkboxes) on the second small window which I all need to click on. I tried to find them via xpath but found out that xpath did not work here. All I get in HTML is something like this:
The number in the brackets [] in this case 17232 vary each time, therefore I cannot find a name I can use for the checkbox. I read many articles on stackoverflow and found this peace of code which also did not work.
// click on button
driver.findElement(By.xpath(hyperlink_take_order)).click();
// a second small window popped up
try
{
driver.switchTo().frame(driver.findElement(By.tagName("iframe")));
System.out.println("change to iframe worked");
List<WebElement> CHECKBOXlist = driver.findElements(By.xpath("//input[#type='checkbox']"));
for(WebElement checkbox : CHECKBOXlist)
{
System.out.println("there was a checkbox");
System.out.println(checkbox.getAttribute("name"));
checkbox.click();
}
driver.switchTo().defaultContent();
}
catch (Exception e)
{
System.out.println("there was no checkbox");
}
driver.findElement(By.xpath("//a[contains(text(),'accept')]")).click();
<div class="md-checkbox product-service md-theme-whitebackground">
<div tabindex="0" class=md-checkbox-container">
<input name="service[17232]" tabindex="-1" id="service_17232" type="checkbox" value ="1" />
</div>
<label class="md-check-label" for="service_17232">This one is blue</label>
</div>
Do you have any idea how I can simply click on all (sometimes multiple) checkboxes on the second small window? Thanks
I am using Selenium to automate the checkout process of a website and can not figure out how to select this certain element properly. So far I have tried all of the following with no luck:
//no such element
driver.findElement(By.id("Something here")).click();
//no such element
driver.findElement(By.xpath("//*[#id="add-remove-buttons"]/input")).click();
//no such element
driver.findElement(By.name("commit")).click();
It seems like the closest I've gotten is with:
driver.findElement(By.className("button")).click();
Using this gives me an error saying the button is not visible. So it looks like I'm heading in the right direction with this, but I'm not sure where to go from here. Here is the HTML source of the button:
<input type="submit" name="commit" value="add to cart" class="button">
not sure if this plays a part in it but when this button is clicked it changes into a new button. The same location, but different color, text, and functionality.
If you wanted to take a look for yourself here is the website:
http://www.supremenewyork.com/shop/accessories/yf89tm27c/e8c56njah?alt=0
and the button I am trying to click is the add to cart button.
Try the following code:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.name("commit")));
button.click();
Hope it helps you!
I am having trouble with figuring out how to click a button on a website.
The buttons code is
<button ng-click="form.submit(false, frm, buyQuery, ['call'])"
ng-mouseleave="hideDir()" ng-mouseover="showDir('call')"
ng-disabled="disabledControls.buyBtn">
<i ng-class="{'mr0':chartHeight <= smallH.smallBuyBtns}"></i>
<span ng-show="chartHeight > smallH.smallBuyBtns">Call</span>
</button>
I also ran into something like this but not the same before and I managed to click it with the code
Set form = webbrowser.Document.Body.GetElementsByTagName("form")(0)
Set button = form.GetElementsByTagName("button")(0)
button.click
I'm sorry my question is probably badly put but I am new to coding, If any additional info is required to answer my question please let me know.
What's the conditions for the click event? Is it some other action?
Anyway in that part of the code where you detect that your form submit button should be clicked, just use the same code as it is in ng-click: $scope.form.submit(false, frm, buyQuery, ['call'])
That will work if form is the name of your form.
I need to disable the button based on the selected row of t:dataTable.
This is the javascript method I'm calling on the row selection event
(the button should be disabled if an item in the selected row has a tooltip... it's ugly, but it was the easiest thing to do):
function processUpdateButton() {
if (!$(".selectedRow").length
|| $(".selectedRow").children().find(".tooltip").length){
$(".Update").button({disabled:true});
} else {
$(".Update").button({disabled:false});
};
}
This is the JSF commandLink:
<h:commandLink id="update" styleClass="Update iconButton"
action="#{myBB.update}"
value="#{gui['button.update']}"
tabindex="301"/>
Setting disabled attribute to the button works. The button is greyed out and if I hover the mouse over it, the cursor doesn't change as it does for other links. The problem is, that I can still click it and the method in the backing bean is called. Is there some way to prevent that?
Here's the rendered disabled button:
<a id="mainForm:update"
class="iconButton ... ui-button-disabled ui-state-disabled"
onclick="return myfaces.oam.submitForm('mainForm','mainForm:update');"
href="#" role="button" aria-disabled="true" disabled="disabled">
<span class="ui-button-text">Update</span>
</a>
I should probably remove the onClick attribute, but I don't know how I would be able to reenable it again.
Of course I can check the condition on the server after clicking the Update button, but that's the last resort. It would be nice if I could completely disable the button generated by JSF only from javascript without call to the server.
So I've found the solution. I copied the onclick attribute to another attribute on disabling button and vice versa:
var onclick;
if (!$(".selectedRow").length
|| $(".selectedRow").children().find(".tooltip").length){
$(".Update").button({disabled:true});
onclick=$(".Update").attr('onclick');
$(".Update").attr('onclick2',onclick);
$(".Update").removeAttr('onclick');
} else {
$(".Update").button({disabled:false});
onclick=$(".Update").attr('onclick2');
$(".Update").attr('onclick',onclick);
$(".Update").removeAttr('onclick2');
};
As you can see the generated html code is not a button but hyperlink. So you need to remove the link from link tag. Could try follows:
$(".Update").removeAttr('href');
i have following code in jsp used with struts2 radio button i want to know which radio button is selected in my action class so can anyone give me solution on this.
code:
<div>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'Postponed To'}"/>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'Suspended'}"/>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'cancelled'}"/>
</div>
i use diffrent radio with same name so that are displayed each in new row...
I dint understand why you need all the radio buttons with the same name.. If the names are different add the getter/setter for all the radio buttons in the actions with there same names, the in action exectute() method check the values of the radio button for true or false as
if(formFieldRadio == true)
u get to know its checked or not
You are doing it wrong, you should do it like this:
<s:radio name="selectAction" list="#{1:'Postponed To', 2: 'Suspended', 3: 'cancelled'}" />
Then in your action you should expect a numeric value (in this case, 1, 2 or 3) in an selectAction variable.
make sure you have the theme="simple" attribute so you can play freely with your css.