Select was changed to select2 and broke my dropdown list test - selenium

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!

Related

How to click on checkbox span class using VBA Selenium

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

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.

Robot Framework Test Data Editor - Click on SPAN/Div not working

I wanted to perform click on Panel element in Selenium Robot Framework
code below:
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<span href="#panel" data-parent="#accordion" data-toggle="collapse" class="accordion-toggle panelTitle collapsed" id="panel" aria-expanded="false">Text 1<span class="toggle-icon"><i class="fa fa-plus-circle"></i></span>
</span>
</h4>
</div>
I want perform a click on "span" tag the whenever I write in my selenium robot framework as
Click Link (in first column) id=panel (in second column)
It doesn't work.
In my previous projects it was working fine but I am not able to make it work in this.
This is pretty hard to answer without you providing your test code or more detail but I suspect the element doesn't exist on the page when you try to click it? What error message are you getting? Providing this can help get an answer quicker.
Reading your question closer, are you using the right keyword, are you actually clicking a link? i.e. something contained in link tags? e.g.
all we've done together
Here's a rudimentary example:
Wait Until Page Contains Element panel 10
Click Element panel
This link should help you find further information if you require it: http://robotframework-seleniumlibrary.googlecode.com/hg/doc/SeleniumLibrary.html?r=2.8#Page Should Contain Element
Other libraries contain similar keywords you could use like the Selenium2Library

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

Selenium webdriver : Unable to click a link (Not inside iframe- able to print gettext value from the webelement)

Please don't make comments regarding why i posted a similar question. I have tried many things and nothing is working. Below is the HTML
<div id="businessSettingsColumn1">
<div class="sectionLink">
Business details
</div>
<div class="sectionLink">
Operating hours
</div>
<div class="sectionLink">
Closed dates
</div>
<div class="sectionLink">
Appointment notifications
</div>
I need to click the second link
I have tried
1) webdriver.findElement(By.partialLinkText("Operating hours")).click();
2)webDriver.get(mylement.findElement(By.tagName("a")).getAttribute("href"));
3)
List<WebElement> businessLinks= busCol.findElements(By.className("sectionLink"));
for(WebElement bLink :businessLinks) {
if(bLink.getText().contains("Operating hours")) {
bLink.findElement(By.tagName("a")).click();
}
}
4) Using the Action builder to move the mouse and then doing a click
Also when i did this 3 times in a row , my element got clicked
webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();
I am using Firefox version 25.0 and Selenium version 2.35.0. Funny thing though is when i do a sysout , the values get printed and when i try to get the url using webdriver I get "Element not found in the cache - perhaps the page has changed since it was looked up" .. its pretty much a static page with links only so i dont understand why i am not able to click it.. Any help will be much appreciated.
Can you try calling focus() on the element before you click on it?
This usually occurs because the element was there at some point, but then something happened and then it's no longer there for some reason. I encounter this frequently when a page makes AJAX calls for example.
Have you tried adding some waits so that selenium is sure that the element is ready?