com.google.gwt.user.client.Element removes quotes in attributes when Application works on IE. I have element with <div id="mytestid"> </div>. I want to remove this id and set a new one, but when app runs on IE (I use IE9) I can not change the id properly because it puts single or double quotes around my id.
For example:
Element el = elem;
el.removeAttribute("id");
String id = "\"mynewid"\"; //I tried all possible combinations foe escaping
el.setAttribute("id", id);
But Element id is id='"mynewid"' - it puts single quotes around double quotes.
Thank you in advance!
What is wrong with this?
Its working as expected. You have set it "mynewid" by using id = "\"mynewid\"".
Try this one if you don't want double quotes around new id.
Element el = elem;
el.removeAttribute("id");
String id = "mynewid";
el.setAttribute("id", id);
Screenshot - Firefox 26.0
Screenshot - IE9
Related
I have an issue that I try to resolve.
I have a page with 4 dropdowns.
and I want to select value in each one og them.
Since the site is angular I used operation to open a drop down and other to select value.
the problem is that after clicking the dropdown to open, all the values are under the same xpath.
( the values generated after pressing the dropdown)
Example dropdown 1 19 values:
Pressing drop down 2 32 values with the same xpath
The problem is after filling dropdown 1, and passing to dropdown 2, the xpath is the same but values not changed quickly enough, So I press drop down 2 and selenium try to find values, but see values of first dropdown.
How can I make selenium (not with thread sleep) to wait until my value exists in the dropdown.
This is my code for searching a value in webelements list (meanning the drop down)
public static void clickOptionInListByXpath(String Xpath, String clickedValue)
{
Integer flag = 1;
WebElement option2;
WebDriver driver2 = WebDriverMgr.getDriver();
List<WebElement> dropdownOptions = driver2.findElements(By.xpath(Xpath));
// for (WebElement option : dropdownOptions )
for(int i= 0;i<dropdownOptions.size() && flag == 1;i++)
{
option2 = dropdownOptions.get(i);
System.out.println("\n Option is: " + option2.getText());
if(option2.getText().equals(clickedValue))
{
option2.click();
flag = 0;
}
}
}
This it my code for waiting text to be seen in single element by xpath with 1 results, not in list (xpath for more than 1 element)
public static void getWebElementByXpathWithWaitTextToBeSeen(String xpath,String text)
{
WebDriver driver2 = WebDriverMgr.getDriver();
// driver2.manage().timeouts().implicitlyWait(IMPLICIT_WAITE, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver2,EXPLICIT_WAITE);
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(xpath),text));
}
How I can wait until text exists in web elements list? and it will refresh the list every time ?
p.s I use sleep it will work however I want code without hard coded sleep
regards
Let me clarify the preconditions first and please correct me if I am wrong:
You have 2 identical web-elements on page that represent 2 drop-downs.
Each of them can generate N web-elements which are all identical in scope of the whole document.
The issue is: when you get all the drop-down options, there is no way to identify from which drop-down they are.
Based on given amount of information I may offer you to start from finding both drop-down elements first, and keeping references to them till you have done all your tests with them.
In this case you will be able to find not all the options, but options that are children of specific drop-down, e.g. using
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#visibilityOfNestedElementsLocatedBy-org.openqa.selenium.WebElement-org.openqa.selenium.By-
Summarizing - find both drop-downs first, and then look for the values not only by xpath, but xpath + parent dropdown.
Ok,i am developing spring MVC based web application, application shows data is list, and i also facilitate filter options to enhanced search functionality, I also remove extra space by using trim(), but what happening now, when user input data in text field and enter the corresponding result will be displayed into the list, but if space added after input, the result will be "NOT FOUND" even i handle the space in javascript too
Java Code which fetches data from database
if (searchParamDTO.getRegNO().trim() != null && !searchParamDTO.getRegNO().trim().equals("") && !searchParamDTO.getRegNO().trim().equals("null")) {
query += " AND UR.REG_UNIQUE_ID = :REG_UNIQUE_ID ";
param.addValue("REG_UNIQUE_ID", searchParamDTO.getRegNO());
}
JavaScript Code: fetches the value in behalf of id
function setSearchParameters() {
regNo = $('#regNo').val().trim();}
i also attached two screenshot with spaces and without spaces
Without space
With space
As #Greg H said you're trimming the string when checking if it's blank, but then adding the raw string to the query which will include any trailing spaces.
Then, this line param.addValue("REG_UNIQUE_ID", searchParamDTO.getRegNO()); should be replaced by param.addValue("REG_UNIQUE_ID", searchParamDTO.getRegNO().trim());
I want to retrieve a title from a div, a start hour and an end hour all of that from a big div called day and inside another div called event
I need to had these items to a list but right now i'am stuck here because it can't retrieve my 3 elements.
Document doc = Jsoup.connect("http://terry.gonguet.com/cal/?g=tp11").get();
Elements days = doc.select("div[class=day]");
Elements event = doc.select("div[class=event]");
for(Element day : days)
{
System.out.println(" : " + day.text());
for(Element ev : event)
{
Element title = ev.select("div[class=title]").first();
Element starthour = ev.select("div[class=bub right top]").first();
Element endhour = ev.select("div[class=bub right bottom]").first();
System.out.println(title.text()+starthour.text()+endhour.text());
}
}
None of there is no div in that document which have only day as class argument. They all have day class combined with another class which prevents div[class=day] from finding such div. Same problem applies to div[class=event] selector.
To solve it use CSS query syntax in which . operator is used to describe class attribute
(hint: if you want to select element which has few classes you can use element.class1.class2).
So instead of
select("div[class=day]");
select("div[class=event]");
use
select("div.day");
select("div.event");
Also instead of
ev.select("div[class=bub right top]");
ev.select("div[class=bub right bottom]");
you could try using
ev.select("div.bub.right.top");
ev.select("div.bub.right.bottom]");
This will allow you to find div which has all these classes (even if they are not in same order or there are more classes then mentioned in selector).
I've gone through the related questions on this site but haven't found a relevant solution.
When querying my Solr4 index using an HTTP request of the form
&facet=true&facet.field=country
The response contains all the different countries along with counts per country.
How can I get this information using SolrJ?
I have tried the following but it only returns total counts across all countries, not per country:
solrQuery.setFacet(true);
solrQuery.addFacetField("country");
The following does seem to work, but I do not want to have to explicitly set all the groupings beforehand:
solrQuery.addFacetQuery("country:usa");
solrQuery.addFacetQuery("country:canada");
Secondly, I'm not sure how to extract the facet data from the QueryResponse object.
So two questions:
1) Using SolrJ how can I facet on a field and return the groupings without explicitly specifying the groups?
2) Using SolrJ how can I extract the facet data from the QueryResponse object?
Thanks.
Update:
I also tried something similar to Sergey's response (below).
List<FacetField> ffList = resp.getFacetFields();
log.info("size of ffList:" + ffList.size());
for(FacetField ff : ffList){
String ffname = ff.getName();
int ffcount = ff.getValueCount();
log.info("ffname:" + ffname + "|ffcount:" + ffcount);
}
The above code shows ffList with size=1 and the loop goes through 1 iteration. In the output ffname="country" and ffcount is the total number of rows that match the original query.
There is no per-country breakdown here.
I should mention that on the same solrQuery object I am also calling addField and addFilterQuery. Not sure if this impacts faceting:
solrQuery.addField("user-name");
solrQuery.addField("user-bio");
solrQuery.addField("country");
solrQuery.addFilterQuery("user-bio:" + "(Apple OR Google OR Facebook)");
Update 2:
I think I got it, again based on what Sergey said below. I extracted the List object using FacetField.getValues().
List<FacetField> fflist = resp.getFacetFields();
for(FacetField ff : fflist){
String ffname = ff.getName();
int ffcount = ff.getValueCount();
List<Count> counts = ff.getValues();
for(Count c : counts){
String facetLabel = c.getName();
long facetCount = c.getCount();
}
}
In the above code the label variable matches each facet group and count is the corresponding count for that grouping.
Actually you need only to set facet field and facet will be activated (check SolrJ source code):
solrQuery.addFacetField("country");
Where did you look for facet information? It must be in QueryResponse.getFacetFields (getValues.getCount)
In the solr Response you should use QueryResponse.getFacetFields() to get List of FacetFields among which figure "country". so "country" is idenditfied by QueryResponse.getFacetFields().get(0)
you iterate then over it to get List of Count objects using
QueryResponse.getFacetFields().get(0).getValues().get(i)
and get value name of facet using QueryResponse.getFacetFields().get(0).getValues().get(i).getName()
and the corresponding weight using
QueryResponse.getFacetFields().get(0).getValues().get(i).getCount()
In a Java program, i am processing an xml using dom4j.
Now, I want to update an attribute of an element.
This is the code I am using to obtain that element--
SAXReader reader = new SAXReader();
doc = reader.read(new StringReader(xmlinput));
Element root = doc.getRootElement();
for ( Iterator i = root.elementIterator( "cloudwhile" ); i.hasNext(); ) {
Element foo = (Element) i.next();
Now, I want to update the value of an attribute of element 'foo'--
For this I am trying to use the following code--
foo.setAttributeValue("indexstart", (String) newstart );
However the above method is deprecated... how do I update the attribute now? Also, I want to take the string representation of the modified xml, immediately after updating the attribute of element 'foo'- how do I do that?
JavaDoc says to use addAttribute(...) instead. The name is somewhat misleading, as it will replace the content of an existing attribute - what is equal to updating a value.
Adds the attribute value of the given fully qualified name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.
As it says in the docs, use addAttribute(String attributeName, String value) instead.