I'm trying to find the web element "Grupo de Parâmetros" but when I use selenium IDE to locate the xpath:idRelative //div[#id='menu']/ul/li[6]/ul/li[4]/ul/li/ul/li[2]/a/span or xpath:postion //li[6]/ul/li[4]/ul/li/ul/li[2]/a/span does not occur anything . I'm using eclipse/java.
This is the code of page
<li class="ui-menuitem ui-widget ui-corner-all ui-menuitem-active" role="menuitem">
<a class="ui-menuitem-link ui-corner-all ui-state-hover" onclick="PrimeFaces.ab({source:'menu',global:false,params: [{name:'menu_menuid',value:'5_3_0_1'}],formId:'j_idt8'});return false;" href="#" title="" tabindex="-1">
<span class="ui-menuitem-text">**Grupo de Parâmetros**</span>
</a>
</li>
And this is my automatized test
driver.get(...);
driver.findElement(By.xpath("//div[#id='menu']/ul/li[6]/ul/li[4]/ul/li/ul/li[2]/a/span"));
driver.findElement(By.id("paramGroupAlias")).clear();
driver.findElement(By.id("paramGroupAlias")).sendKeys("box");
driver.findElement(By.id("pesquisar")).click();
WebElement retorno = driver.findElement(By.id("j_idt64_data"));
System.out.println(" Retorno "+ retorno.getText() );
I also tried this but I also couldn't make it from Selenium IDE when I exported it so I programmed it in my Java proyect with JQuery. I think it will be good for you something like this:
#ui-menuitem ui-widget ui-corner-all ui-menuitem-active > a > span
Where you reference the class of the first element of your page and you descend "levels" in the page.
But I also made reference to the object that I wanted to refer to like this:
#ui-menuitem-text
I used it in my Java project and it worked but I tried this with 3 'divs' one inside the others. Anyway, I think it will work to you.
Please let me know if it works.
Related
I am having serious trouble using the regular selenium webdriver on one page of my application which is build with Angular. I have added the dependency of ngwebdriver in my pom.xml and so far I have solved some of the issues. Only with the drop-down, I still haven't figured out how to do this. This is the drop-down I am talking about:
<d3-data-list _nghost-c8="" ng-reflect-data-source="[object Object]" ng-
reflect-html-id="documents_glossary_entityPicke" ng-reflect-allow-blank-
option="true" ng-reflect-blank-option-text="All entities" ng-reflect-default-
caption="Choose an entity"><div _ngcontent-c8="" class="dropdown d3-data-
list" id="documents_glossary_entityPicker">
<button _ngcontent-c8="" aria-expanded="true" aria-haspopup="true" class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button" id="documents_glossary_entityPicker_button">
All entities
<span _ngcontent-c8="" class="caret"
id="documents_glossary_entityPicker_caret"></span>
</button>
<ul _ngcontent-c8="" aria-labelledby="dropdownMenu1" class="dropdown-menu"
ng-reflect-infinite-scroll-handle-in-progress="false"
id="documents_glossary_entityPicker_dropdown">
<!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c8="">
<a _ngcontent-c8=""
id="documents_glossary_entityPicker_blank_option">All entities</a>
</li>
then the options from the drop-down are like this:
</li><li _ngcontent-c8="">
<a _ngcontent-c8="" id="documents_glossary_entityPicker_option_2">Entity three</a>
</li>
The problem is that the order of the elements in my drop-down is not maintained because if an element (entity) is edited on another page then it will be at the bottom of the list. So I can never really know where exactly my element is in the drop-down list.
Is there something like browser.findElement(ByAngular.buttonText("text")) which I can use in my case? Thanks.
I guess you're looking for the filter() or .reduce() possibilities.
For .reduce() check the example here
For .filter() your code should look something like this:
element.all(by.css('ul li a')).filter(function (elm) {
return elm.getAttribute('value').then(function (text) {
return text === "TheValueYouLookFor";
});
}).first().click();
I didn't test this .filter myself, but it's pretty straight forward from the Protractor documentation.
I'm trying to get selenium to click the select button but I can't use by.linkText() because there are two buttons with the same name.
I'm using this xpath ".//*[contains(#id,'view-something_111111_2A22DF2_)']/div/a[text()='Select']"; to find the button but it can't find it.
I've also tried ".//*[contains(#id,'view-something_111111_2A22DF2_)']/div/a";.
I've looked over the Selenium documentation and can't seem to find a solution.
Here is the section of website code:
<div id="view-something_111111_2A22DF2_0" class="coverage-wrap collapse" aria-expanded="false" style="height: 30px;">...</div>
<div class="btn-raplace">
<a class="btn-beer" data-toggle="collapse" data-target="#view-effectData_111111_2A22DF2_0">Select</a>
for reference, the second Select button has this code:
<div id="view-something_111111_2A3B5DF2_0" class="coverage-wrap collapse" aria-expanded="false" style="height: 30px;">...</div>
<div class="btn-raplace">
<a class="btn-beer" data-toggle="collapse" data-target="#view-effectData_111111_2A3B5DF2_0">Select</a>
which is why I am using the id in my xpath.
Thanks.
You can try this XPATH :- //*[#class="btn-raplace"]/a[#class="btn-beer"][1] here [1] is postion of ur button. Which you want to click
I can see two mistakes in the Xpath you are using.
First Mistake:
.//*[contains(#id,'view-something_111111_2A22DF2_)'] is incorrect.You have placed the single quote at a wrong place. It should be
//div[contains(#id,'view-something_111111_2A22DF2')]
Second Mistake
The element div with the class="btn-raplace" is not the child of the above element. I can see in the HTML that the above element has the closing tags before this element.
Please replace your XPATH with:
//div[contains(#id,'view-something_111111_2A22DF2')]/following-sibling::div[1]/a
Here is the Answer to your Question:
Use this xpath:
//div[#class='btn-raplace']/a[#class='btn-beer']
Let me know if this Answers your Question.
I have this html code below and I want to differentiate between these two PagePostsSectionPagelet as I only want to find web elements from the first PagePostsSectionPagelet. Is there any way I can do it without using <div id="PagePostsSectionPagelet-183102686112-0" as the value will not always be the same?
<div id="PagePostsSectionPagelet-183102686112-0" data-referrer="PagePostsSectionPagelet-183102686112-0">
<div class="_1k4h _5ay5">
<div class="_5sem">
</div>
</div>
<div id="PagePostsSectionPagelet-183102686112-1" class="" data-referrer="PagePostsSectionPagelet-183102686112-1" style="">
<div class="_1k4h _5ay5">
<div class="_5dro _5drq">
<div class="clearfix">
<span class="_5em9 lfloat _ohe _50f4 _50f7">Earlier in 2015</span>
<div id="u_jsonp_3_4e" class="_6a uiPopover rfloat _ohf">
</div>
</div>
<div id="u_jsonp_3_4j" class="_5sem">
<div id="u_jsonp_3_4g" class="_5t6j">
<div class="_1k4h _5ay5">
<div class="_5sem">
</div>
</div>
Tried using //div[#class='_1k4h _5ay5']//div[#class ='_5sem'] but it will return both.
Using //div[#class='_5dro _5drq']//span[contains(#class,'_5em9 lfloat _ohe _50f4 _50f7') and contains(text(), '')] will help me find the second PagePostsSectionPagelet instead.
you need to use the following xpath:
//div[contains(#class,'_1k4h') and contains(#class,'_5ay5')]
as selenium doesn't work properly with search of several classes in one attribute.
I mean By.Class("_1k4h _5ay5") will found nothing in any case and By.Xpath("//div[#class='_1k4h _5ay5']") can also found nothing in case of class will be "_5ay5 _1k4h" or " _5ay5 _1k4h".(as they possibly generated automatically, its may be have different position on page reload)
But for the best result by performance and by correctness I think will be the following xpath:
".//div[contains(#id, 'PagePostsSectionPagelet')][1]" -- for first div
".//div[contains(#id, 'PagePostsSectionPagelet')][2]" -- for second div
I see that dynamic in the div id is only the number so you can use something like:
WebElement element = driver.FindElements(By.XPath("//div[contains(.,'PagePostsSectionPagelet')])")[1];
This will take only the first web element.
Try using a css selector as below and refine further if required.
The code below returns a List of matching WebElements and then you grab the first one in the List.
List<WebElement> listOfElements = driver.findElements(By.cssSelector("div[data-referrer]"));
WebElement myElement = listOfElements.get(0);
Hint: use the Chrome console to test your css and xpath selectors directly. e.g. use
$$("div[data-referrer]") in the console to reveal what will get selected.
I am trying to open different section of page. These Section will open on click of different tabs.
Below is HTML Structure of Page
<div id="MainContentPlaceHolder_divMainContent">
<div id="MainContentPlaceHolder_tbCntrViewCase" class="Tab ajax__tab_container ajax__tab_default" style="width: 100%; visibility: visible;">
<div id="MainContentPlaceHolder_tbCntrViewCase_header" class="ajax__tab_header">
<span id="MainContentPlaceHolder_tbCntrViewCase_tbPnlCaseDetails_tab" class="ajax__tab_active">
<span id="MainContentPlaceHolder_tbCntrViewCase_tbPnlVehicle_tab" class="ajax__tab_hover">
<span class="ajax__tab_outer">
<span class="ajax__tab_inner">
<a id="__tab_MainContentPlaceHolder_tbCntrViewCase_tbPnlVehicle" class="ajax__tab_tab" style="text-decoration:none;" href="#">
<span>Vehicle</span>
</a>
</span>
</span>
</span>
and I have Written Below Lines but these are not working
driver.findElement(By.id("__tab_MainContentPlaceHolder_tbCntrViewCase_tbPnlVehicle")).click();
driver.findElement(By.xpath("//a[text()='Vehicle']")).click();
I got Source Not Found Error
As per the OP's comments, I am posting the xpaths that can be used to locate the concerned element :
1- //span[#id='MainContentPlaceHolder_tbCntrViewCase_tbPnlVehicle_tab']//span[.='Vehicle']
This will locate the span element with innerHTML/text as Vehicle which is a descendant of span with id MainContentPlaceHolder_tbCntrViewCase_tbPnlVehicle_tab
OR
2-//span[#id='MainContentPlaceHolder_tbCntrViewCase_tbPnlVehicle_tab']//span[.='Vehicle']/..
This will locate the parent of span element with innerHTML/text as Vehicle which is a descendant of span with id MainContentPlaceHolder_tbCntrViewCase_tbPnlVehicle_tab which in this case is an a element.
Please check if this works for you. Else, let me know how many matching nodes does it show, when you use them. We will sort this one out.
I have recorded an automatic test with Selenium, exported it into JAVA code and now I am fighting to complete it. The problem is that I cannot get click(); done.
This is my code, a part of it:
try {
assertTrue(driver.findElement(By.xpath("//*[text()='Nowa oferta dokument']"))
.getText().matches("^Nowa oferta dokument$"));
} catch (Error e) {
verificationErrors.append(e.toString());
}
driver.findElement(By.xpath("//*[text()='Nowa oferta dokument']")).click();
First I find the element using xpath and then using xpath I want to click on it so its settings open.
I have tried many ways to solve it, and still can't figure it out. Do you see any solution for this one?
HTML:
<p class="photo"><img src="img/document.png"></p>
<p class="name">Nowa oferta dokument</p>
<p class="price">123 zł</p>
<div class="rate ctrlViewRateOffer" data-value="0.0000">
<span class="stars"></span>
<span class="stars"></span>
<span class="stars"></span>
<span class="stars"></span>
<span class="stars"></span>
</div>
<p class="date"></p>
<div class="hide info">
<p></p>
<p><a class="ctrlClickSubmit delete" title="Usuń" data-value="delete_1007" data-form="formManageOffer" href="#"></a></p>
<p></p>
<p class="type">e-book</p>
<p>To jest opis nowo tworzonej oferty - dokumentu, który wystawię na sprzedaż, a następnie u...</p>
</div>
<div class="bgInfo"></div>
Most probable reason is that
By.xpath("//*[text()='Nowa oferta dokument']")
is matching more than one element...
Also, check if the returned element/s is clickable
Well, your selector is wrong for one:
driver.findElement(By.xpath("//*[#class='name'][text()='Nowa oferta dokument']")).click();
Should hopefully work. If not, your element is probably not clickable due to other elements in front of it.
In which case, you can simulate the click using javascript:
driver.executeScript("arguments[0].click()", driver.findElement(By.xpath("//*[#class='name'][text()='Nowa oferta dokument']")));
Your CURRENT selector IS matching multiple elements. Since the element you are trying to select is at least two elements in, it is matching every parent object in the tree above the element you actually want, since they ALL contain that as the text().