How to click on checkbox span class using VBA Selenium - vba

enter image description here
htmlcode:
How can i check all checkbox in this tables (on pic)?
vba code and selenium.
thanks alot
bot.FindElementByClass("ui-chkbox-icon ui-icon ui-icon-blank ui-c").Click
its not work.

See if this helps
driver.FindElementByXPath(".//span[#class='ui-chkbox-icon ui-icon ui-icon-blank ui-c']").Click
If not, try to click on the div. Assuming the div class is unique
driver.FindElementByXPath(".//div[#class='ui-chkbox-box ui-widget ui-corner-all ui-state-default']").Click

Related

span inside a button tag not clickable using selenium webdriver?

I'm trying to click and "Add Course" labelled button using selenium webdriver but it is not working out for me.
Here's the snippet I took from chrome developer tools:
<button type="button" class="btn btn-green" onclick="javascript:AddCourse();">
<span class="glyphicon glyphicon-plus-sign">
::before
</span>
<span translate="portallang_addCourse" class="open-sans ng-scope">
"Add Course"
</span>
</button>
You need one of the following xpaths:
First choice:
//span[contains(text(), 'Add Course')]
These two, only if there are always 2 spans and the second span is always Add Course:
(//button[#class='btn btn-green']/span)[2]
//button[#class='btn btn-green']/span[2]
Slowest option as the entire document is scanned. Add Course can only occur once on the page:
//*[contains(text(), 'Add Course')]
What error are you getting? What property did you use to click on the span element?
You got to use xpath for such elements.
Use xPath Finder add-on for Chrome and extract the unique xpath for this element:
https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=en
You can always write an unique xpath manually but this just saves time and is accurate.
Hope this helps!

various ways to find elements by using Webdriver #FindBy annotations

I am trying to find the solution for my Webdriver script to work. I need your help to find the solution in my scenario.
I have a web application that creates form by using tabbed screen. There is a Next and Back buttons that have similar attributes and I cant find the solution.
xpath doesn't work, CSS has the same name and its getting confused.
here is the "Next" button that needs to be clicked:
<div class="button" style="margin-right: 5px;">
<input type="button" onclick="javascript:submitForm('metaStudyAction!moveToData.action')" value="Next">
I would like to use #FindBy annotation to find the element. Can I use HOW with multiple attributes?
You can use css for multiple attributes
#FindBy(css = "[type='button'][value='Next']")
private WebElement button;

Select was changed to select2 and broke my dropdown list test

Getting error: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
public analyticsLandingPage verifyReportingProfile() throwsInterruptedException{
Select select = new Select(driver.findElement(By.className("select2-choice")));
select.selectByVisibleText("Arria");
return PageFactory.initElements(driver, analyticsLandingPage.class);
}
This is my HTML page:
<div id="s2id_reporting_profile_id" class="select2-container select2-allowclear reporting_profile select2-container-active"
style="width: 50%;">
<a class="select2-choice" tabindex="-1" href="javascript:void(0)">
<span id="select2-chosen-7" class="select2-chosen">AdOps Reporting Profile</span>
<abbr class="select2-search-choice-close"/>
How can I make it work ? I need it to click on dropdown list and select element. Thanks
Usually this is caused because you have to click a button on the front-end before Selenium can register the dropdown. A lot of times this is caused by a javascript call. Have you tried clicking on the div:
id="s2id_reporting_profile_id"
And then clicking on the select2-choice option?
It could also be this:
select.selectByVisibleText("Arria");
Is there text visible on that element after you click it? Or does another element show up from href="javascript:void(0)" when select gets clicked? If that's the case you need to click it in Selenium.
If this doesn't help, your question is very vague, maybe you could edit it to have it make more sense? Help us help you trouble shoot the problem!

selenium click using span class or onclick

I am a newbie to java and selenium webdriver. I am having an issue clicking an image. Below is the page source.
<a href="javascript:void(0);">
<span class="HomeButton" onclick="javascript:onBtnHomeClick();"/>
</a>
I tried below codes but did not work and still getting the Unable to locate element error.
driver.findElement(By.xpath("//a[#onclick='onBtnHomeClick()']")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/span"))).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("HomeButton"))).click();
I have to click the homebutton. Any help would be much appreciated
I don't know why By.className("HomeButton") didn't work but you have errors in the other two.
In driver.findElement(By.xpath("//a[#onclick='onBtnHomeClick()']")).click(); the tag for onclick is <span> not <a>. It also not onBtnHomeClick() but javascript:onBtnHomeClick();
driver.findElement(By.xpath("//span[#onclick='javascript:onBtnHomeClick();']")).click();
If you want to use onBtnHomeClick() use contains
driver.findElement(By.xpath("//span[contains(#onclick, 'onBtnHomeClick')]")).click();
Or
driver.findElement(By.cssSelector("onclick*='onBtnHomeClick'")).click();
And in wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/span"))).click(); the <span> parent tag is <a>, not <div>
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/a/span"))).click();
You simply need the correct locator IF your element will be eventually visible.
Xpath = "//span[contains(#class,'HomeButton') and contains(#onclick,'onBtnHomeClick')]"
Add wait as needed above exanmple, that should work.

Failed click using Selenium and XPath

For test automation on a web app I am currently using Robot framework and the Selenium library. There comes the moment I want to click on a button and then I wait for an element to appear. Alas, the click, although recorded successful in the log, does not lead to the apparition of the element I wish. In fact it is as if the click never happened.
To click on the button, I retrieve it using xpath. Using Firepath I successfully verified that the element is unique and does exist but what it shows leads me to think I have found why the button is not clicked correctly
You can see in light blue the button I want to click on and wrapped with dotted line the zone detected by firepath.
Is it possible that the click is done next to the button instead on it ?
Here is the incriminated line :
Click Element xpath=(.//button[contains(#id,'editContract')])[1
Edit :
HTML of the page :
<button id="listContractTableForm:listContractTable:0:editContract" name="listContractTableForm:listContractTable:0:editContract" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" onclick="window.location.href='destinationPage?faces-redirect=true&contractEntityContractId=678'">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-search"></span>
<span class="ui-button-text ui-c">ui-button</span>
</button>
Assuming you want the span with class containing ui-button-icon-left ui-icon ui-c ui-icon-search
//button[contains(#id,'listContractTableForm')]/span[contains(#class,'ui-icon-search')]
if you want the span with class="ui-button-text ui-c" simply change the class in the xpath