Allready tried "intro to css locators in selenium" and "css selectors for selenium"but they did not bring a solution. When using Selenium IDE 2.91 to record a webpage test, playing back the scenario ends in errors. IMHO the problem is a push button with aria-pressed that changes when hovering over it, pressed or unpres it. When doing those things the div class is changing from:
<div class="gwt-PushButton A gwt-PushButton-up" tabindex="0" role="button" style="" aria-pressed="false">
To
<div....gwt-PB-up-hovering tabindex="0" role="button" style="" aria-pressed="false">
And to
<div class="gwt-PushButton A gwt-PushButton-down-hovering" tabindex="0" role="button" style="" aria-pressed="true">
Rest of html code within the div is:
<input tabindex="-1" role="presentation" style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;" type="text">
<div class="html-face">Controle</div>
</div>
Record of selenium is 2 records:
1 click //div[5]/div[2]
2 click //div[5]/div[2]/div
The info selenium gives = [info] Executing: |click | //div[5]/div[2] |
| But because the button isnt really clickt on the next step goes in
error.
Any suggestions how to be able to make selenium click the button?
Already tried click using css=div.gwt-PushButton.GBKHVCADO2
Related
I am having some trouble selecting a hidden menu item on a work webpage using SeleniumBasic for vba. I have tried to use WebDriver.Mouse.MouseTo to hover over each menu option so that I can select the object nested "beneath" it, but after the first hover the object cannot be found.
In the picture below I intend to navigate like this:
Pricing Admin
System Admin
Multi-PAG Upload
To do this, I have to hover over Pricing Admin and subsequently hover over System Admin so that menu appears to click on Multi-PAG Upload. I have successfully gotten the driver to hover over Pricing Admin which brings up first menu list with three items ending in System Admin. However, trying to FindElement() for System Admin so that I can hover on it has proven very difficult.
I tend get an object required error or an XPath selector invalid depending on the method that I attempt. I start having problems at Set systemAdmin =.
Any advice would be welcome!
Public Sub SeleniumTest()
Dim driver As New WebDriver
'open chrome to site
driver.start "chrome"
driver.Get "http://www.website.net"
'login
driver.FindElementByName("j_username").SendKeys ("user")
driver.FindElementByName("j_password").SendKeys ("pass")
driver.FindElementById("submit_button").Click
'hover over Pricing Admin
Dim pricingAdmin As WebElement
Set pricingAdmin = driver.FindElementById("prcngAdmMnuFrm:prcngAdmMnu")
driver.Mouse.MoveTo pricingAdmin
Dim systemAdmin As WebElement
'neither selection method below works properly
' Set systemAdmin = driver.FindElementByXPath("//*[contains(text(),'System Admin')]")
' Set systemAdmin = driver.FindElementByXPath("//div[#id='prcngAdmMnuFrm:prcngAdmMnu']/div/div/ul/li/ul/li[3]/ul/li[4]/a/span/span")
driver.Mouse.MoveTo systemAdmin
Dim multiPagUpload As WebElement
' Set multiPagUpload = driver.FindElement("??")
multiPagUpload.Click
'closes browser window
driver.Quit
End Sub
Here is the (abridged) HTML for the site. I trimmed out a bit of the lists for simplicity's sake but if it's actually necessary (for using javascript, etc) let me know and I can pop more in.
<div id="prcngAdmMnuFrm:prcngAdmMnu" style="">
<div class="ui-widget ui-widget-content wijmo-wijmenu ui-corner-all ui-helper-clearfix wijmo-wijmenu-horizontal" aria-activedescendant="ui-active-menuitem" role="menubar">
<div class="scrollcontainer checkablesupport">
<ul style="display: block;" class="wijmo-wijmenu-list ui-helper-reset" tabindex="0">
<li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all wijmo-wijmenu-parent" aria-haspopup="true" style="">
<a href="#" class="wijmo-wijmenu-link ui-corner-all" id="">
<span class="wijmo-wijmenu-text">
<span class="wijmo-wijmenu-text">Pricing Admin</span>
</span>
<span class="ui-icon ui-icon-triangle-1-s"></span>
</a>
<ul class="wijmo-wijmenu-list ui-widget-content ui-corner-all ui-helper-clearfix wijmo-wijmenu-child" style="display: none; left: 0px; top: 38px; position: absolute; list-style-type: none;" aria-hidden="true">
<li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all wijmo-wijmenu-parent" aria-haspopup="true" style="">
<a href="#" class="wijmo-wijmenu-link ui-corner-all ui-state-focus">
<span class="wijmo-wijmenu-text">
<span class="wijmo-wijmenu-text">System Admin</span>
</span>
<span class="ui-icon ui-icon-triangle-1-e"></span>
</a>
<ul class="wijmo-wijmenu-list ui-widget-content ui-corner-all ui-helper-clearfix wijmo-wijmenu-child" style="display: none; left: 215px; top: -1px; position: absolute; list-style-type: none;" aria-hidden="true">
<li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all">
<a onclick="showProcessingMessage('Loading');;var self = this; setTimeout(function() { var f = function(opt){ice.ace.ab(ice.ace.extendAjaxArgs({"source":"prcngAdmMnuFrm:menu_pad_sa_multi","execute":'#all',"render":'#all',"event":"activate"}, opt));}; f({node:self});}, 10);" style="cursor:pointer;" class="wijmo-wijmenu-link ui-corner-all">
<span class="wijmo-wijmenu-text">
<span class="wijmo-wijmenu-text">Multi-PAG Upload</span>
</span>
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<script type="text/javascript">
var widget_prcngAdmMnuFrm_prcngAdmMnu = ice.ace.create("Menubar", ["prcngAdmMnuFrm:prcngAdmMnu", {
"autoSubmenuDisplay": true,
"direction": "auto",
"animation": {
"animated": "fade",
"duration": 400
}
}]);
</script>
</div>
If I've left anything out that you need to troubleshoot, please let me know!
The xpath which is used in the code is not correct. my suggesting to find the anchor element and move the mouse over.
# System Admin Menu
'Hover over Pricing Admin
Dim systemAdmin As WebElement
Set systemAdmin = driver.FindElementByXPath("//a[.//span[contains(.,'System Admin')]]")
driver.Mouse.MoveTo pricingAdmin
If the mouse hover does not work, we can still try to handle the menu by clicking on the anchor element and then sendkeys (keys.Arrow_Right)
#Multi-PAG Upload
Dim multiPagUpload As WebElement
Set multiPagUpload = driver.FindElementByXPath("//a[.//span[contains(.,'Multi-PAG Upload')]]")
multiPagUpload.Click
I'm trying to select a tab on webpage created using extjs. FirePath is highlighting the tab correctly but click event is not working. Selenium is throwing element not visible error.
Exception in thread "main"\org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: chrome=57.0.2987.133)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7601 SP1 x86_64)
(WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 38 milliseconds
Here is the HTML code:
I'm trying to select a Tab titled Details with id as tabDetail.
<a class="x-tab x-unselectable x-box-item x-tab-default x-noicon x-tab-noicon x-tab-default-noicon x-top x-tab-top x-tab-default-top x-tab-after-title" role="button" hidefocus="on" unselectable="on" tabindex="0" id="tabDetail" style="right: auto; left: 143px; top: 0px; margin: 0px;">
<span id="tabDetail-btnWrap" class="x-tab-wrap" unselectable="on">
<span id="tabDetail-btnEl" class="x-tab-button">
<span id="tabDetail-btnInnerEl" class="x-tab-inner x-tab-inner-center" unselectable="on">
Detail
</span>
<span role="img" id="tabDetail-btnIconEl" class="x-tab-icon-el " unselectable="on" style="">
</span>
</span>
</span>
</a>
You need to wait until element is visible. Use explicit wait -
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[2]")));
// Now click on element
driver.findElement(By.xpath("//div[2]")).click();
HTML Code for the drop down with 3 constant values:
<div class="a-popover-inner" style="height: auto; overflow-y: auto; min-width: 107px; width: auto;">
<ul id="3_dropdown_combobox" class="a-nostyle a-list-link" aria-multiselectable="false" role="listbox" tabindex="-1">
<li class="a-dropdown-item status-option" role="option" tabindex="0">
<li class="a-dropdown-item status-option" role="option" tabindex="0">
<a class="a-dropdown-link a-active" data-value="{"stringVal":"Active"}" href="javascript:void(0)" tabindex="-1"> Active </a>
</li>
<li class="a-dropdown-item status-option" role="option" tabindex="0">
</ul>
Tried:
driver.findElement(By.xpath("//*[#id='status-select']/span/span"));
Result:
Able to click/select the dropdown successfully
But Unable to further select a specific dropdown
Try1:
driver.findElement(By.xpath("//*a[#data-value={'stringVal':'Active'}]")).click();
Result1:InvalidSelectorError: Unable to locate an element with the xpath expression
Try2:
java.util.List<WebElement> elements = driver.findElements(By.xpath("//*[#id='status-select']/span/span"));
Result3: count = element.size(); // prints count as 1
//so cant get elements[element.count-1];
Try3:
Select select = new Select(driver.findElement(By.id("3_dropdown_combobox")));
select.selectByVisibleText("Expired");
Result3:
Try4:
driver.findElement(By.xpath("//*[#id='3_dropdown_combobox']/li[2]/a")).click();
(or)
java.util.List<WebElement> elements = driver.findElements(By.id("3_dropdown_combobox"));elements.size();
Result4: console does nothing for >10min. I stop the execution
Please Guide me on what is correct way to select 2nd/3rd dropdown options
Do this:
Select select = new Select(driver.findElement(By.id("status-select")));
select.selectByIndex(1); //Selects the 2nd option in the dropdown list
In order to click the Active link this should work for you:
driver.findElement(By.xpath("//*[#id="3_dropdown_combobox"]/li[2]/a")).click();
I tried doing
driver.findElement(By.xpath("//*[#id="3_dropdown_combobox"]/li[2]/a")).getText();
and got the word Active as expected.
Try to see if the link takes you to the correct location
Following works fine in IE, in FF it gives ElementNotVisibleException
driver.findElement(By.xpath("//div[4]/table/tbody/tr[1]/td[2]")).click();
While following works in FF, in IE it doesn't do anything:
WebElement element1 = driver.findElement(By.xpath("//div[4]/table/tbody/tr[1]/td[2]"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element1);
I'm using IE 9.0 (with 32 bit IEDriverServe.exe) and FF 23.0.
Here is the Code:
<div id="popup_12" class="dijitPopup dijitMenuPopup" style="z-index: 1000; right: auto; left: 45px; top: 27px; visibility: visible; display: none;" role="presentation" dijitpopupparent="dijit_MenuBar_0">
<table class="dijit dijitMenu dijitReset dijitMenuTable dijitMenuPassive" cellspacing="0" data-dojo-attach-event="onkeypress:_onKeyPress" tabindex="0" role="menu" widgetid="dijit_Menu_1" style="top: 0px; visibility: visible;">
<tbody class="dijitReset" data-dojo-attach-point="containerNode">
<tr class="dijitReset dijitMenuItem" tabindex="-1" role="menuitem" data-dojo-attach-point="focusNode" aria-labelledby="dijit_PopupMenuItem_1_text dijit_PopupMenuItem_1_accel" style="-moz-user-select: none;" widgetid="dijit_PopupMenuItem_1" aria-haspopup="true">
<td class="dijitReset dijitMenuItemIconCell" role="presentation">
<td id="dijit_PopupMenuItem_1_text" class="dijitReset dijitMenuItemLabel" data-dojo-attach-point="containerNode" colspan="2">XXXXX</td>
<div id="popup_23" class="dijitPopup dijitMenuPopup" style="z-index: 1001; right: auto; left: 117px; top: 0px; visibility: visible; display: none;" role="presentation" dijitpopupparent="dijit_Menu_1">
<table class="dijit dijitMenu dijitReset dijitMenuTable dijitMenuPassive" cellspacing="0" data-dojo-attach-event="onkeypress:_onKeyPress" tabindex="0" role="menu" widgetid="dijit_Menu_2" style="top: 0px; visibility: visible;">
<tbody class="dijitReset" data-dojo-attach-point="containerNode">
<tr class="dijitReset dijitMenuItem" tabindex="-1" role="menuitem" data-dojo-attach-point="focusNode" aria-labelledby="dijit_MenuItem_3_text dijit_MenuItem_3_accel" style="-moz-user-select: none;" widgetid="dijit_MenuItem_3">
<tr class="dijitReset dijitMenuItem" tabindex="-1" role="menuitem" data-dojo-attach-point="focusNode" aria-labelledby="dijit_MenuItem_4_text dijit_MenuItem_4_accel" style="-moz-user-select: none;" widgetid="dijit_MenuItem_4">
<tr class="dijitMenuSeparator" style="-moz-user-select: none;" widgetid="dijit_MenuSeparator_0">
<tr class="dijitReset dijitMenuItem" tabindex="-1" role="menuitem" data-dojo-attach-point="focusNode" aria-labelledby="dijit_MenuItem_5_text dijit_MenuItem_5_accel" style="-moz-user-select: none;" widgetid="dijit_MenuItem_5">
<td class="dijitReset dijitMenuItemIconCell" role="presentation">
<td id="dijit_MenuItem_5_text" class="dijitReset dijitMenuItemLabel" data-dojo-attach-point="containerNode" colspan="2">YYYYY</td>
I have to click Item XXXXX and Item YYYYY
div id with popup_12 and popup_23 changes every time the page is loaded or the item is clicked
Item YYYYY is displayed only when Item XXXXX is clicked
With FF using javascript executor and xpath or CSS selector it works perfectly, however with IE it doesn't
For this to work with IE I have to use xpath or CSS without javascript executor but again this time it doesn't works with FF
XXXXX and YYYYY
int no_of_popups = driver.findElements(By.cssSelector("div[id*='popup']")).size();
for(int i=1;i<=no_of_popups;i++)
{
String text = driver.findElement(By.cssSelector("div.dijitPopup:nth-of-type("+i+
") > table.dijitReset > tbody.dijitReset > tr.dijitMenuItem > td.dijitMenuItemLabel")).getText();
S.O.P(text);
}
You can always see if the element is displayed (visible, not just in the DOM)
el = driver.find_element(:xpath, 'xpath').displayed?
el.click
We have tested thousands of websites and when doing so I have sometimes come across similar limitations within Selenium/WebDriver. XPath is very powerful and we use it on a daily basis however assuming the page is using JQuery, you can do the entire search of the DOM using JQuery Selector and then you don't have to worry if the element is visible or not.
The code could look something like:
driver.executeScript("$('td:contains(\"Foo\")').click();");
I don't recommend walking the DOM the way you have, there are much more efficient was find what you are looking for. However based on what you have above, you could do something like:
driver.executeScript("$($($($('body').find('div')[4]).find('table:first').find('tbody:first').find('tr')[1]).find('td')[2]).click();");
You can read more about jQuery Selectors on their webpage.
Writing scripts for functional testing is easy with the Neustar Local Validator. You can see examples and watch videos on how to do this at: http://community.neustar.biz/community/wpm/getting_started/blog/2013/11/20/neustar-training-videos
Good Luck to you.
Brian Kranson
Neustar, Inc. / Professional Services Engineer
You can use WaitTime or wait for Element as below
int timeout=1;
while(timeout<=60)
{
WebElement element1 = driver.findElement(By.xpath("//div[4]/table/tbody/tr[1]/td[2]"));
if(element1.isDisplayed())
{
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element1);
break;
}
else
{
try {
Thread.sleep(2000);
timeout++;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I wanted to click the date from calendar popup which is inside iframe. I have written below selenium code which throwing unable to locate the element error. Please help me to write correct xpath or selenium code. I am new to Selenium
selenium code:
WebElement iframe =driver.findElement(By.id("NewsSearchDateToInput_selector_iframe"));
driver.switchTo().frame(iframe);
//clicking on date 3
driver.findElement(By.xpath("//div[3][#class='daysNumbersStyles']")).click();
Error: unable to locate the element "//div[3][#class='daysNumbersStyles']"
Html tags:
<iframe id="NewsSearchDateToInput_selector_iframe"
class="dateTimeSelectorContainerStyle altFlexibleContainer"
src="javascript:false;"
style="left: 1216px; top: 245px; width: 249px; height: 207px;
display: block;"/>
<div class="dateTimeSelectorContainerStyle altFlexibleContainer"
style="top: 245px; left: 1216px; display: block;">
<div class="top">
<div class="content">
<div class="dateSelectorHeader">
<div class="dateSelectorBody">
<div class="yearMonthSelectorStyle">
<div id="NewsSearchDateToInput_selector_monthSelector" class="monthSelectorListStyle">
<div class="daysStyle">
<div>
<div class="daysNumbersDivStyle">
<div class="daysNumbersStyles">1</div>
<div class="daysNumbersStyles">2</div>
<div class="daysNumbersStyles">3</div>
does it help ? //div[#class='daysNumbersStyles'][3]
Try this after getting in to frame:
driver.findElement(By.xpath("//div[text()='3']").click();
Edit:
For To selector:
driver.findElement(By.xpath("//*[#id='NewsSearchDateToInput_selector_monthSelector']//div[text()='3']").click();
For From selector:
driver.findElement(By.xpath("//*[#id='NewsSearchDateFromInput_selector_monthSelector']//div[text()='3']").click();