docx4j: is there support for value attribute for ol li element? - docx4j

I have got a document that is going to show double column document. In HTML I am using value attribute of the li element in an ordered list (ol) to control the value counter of. In a two-column document the right column will follow the counter of the left column. It works in HTML, but when converting to word using docx4j, it is not respecting the overridden value attribute.

Looks like you'll need to enhance at https://github.com/plutext/docx4j-ImportXHTML/blob/master/src/main/java/org/docx4j/convert/in/xhtml/ListHelper.java#L603

There is no support for this in docx4j. There is a pull request for this. When the pull request is merged, then this answer will be updated accordingly.
Meanwhile, in order to use this feature, use the maven repository https://jitpack.io and declare the dependency ( in gradle):
implementation("com.github.naimdjon:docx4j-ImportXHTML:8.2.1-li-SNAPSHOT")
in maven:
<dependency>
<groupId>com.github.naimdjon</groupId>
<artifactId>docx4j-ImportXHTML</artifactId>
<version>8.2.1-li-SNAPSHOT</version>
</dependency>

Related

How to select one from duplicate tag in page in java in selenium webdriver

I am using Selenium WebDriver and I have number of items on a page and each item on page is a separate form type.
I have saved all of these form elements in a list and I am iterating over every item in an attempt to get the name of the element by using the "alt" attribute.
However when I try to get the "name" attribute from the input element it is always returning the first input tag found on that page, not the name attribute of the element I have currently selected.
The syntax I am using is:
((Webdriver imgtags.get(i)).findelement(By.xpath("//input[#name='qty']")).sendKeys ("100");
I have also tried to get the id from the tag by using:
((Webdriver imgtags.get(i)).getAttribute("id");
It's returning a blank value, but it should return the value of the id attribute in that input tag.
I also tried to get the id by using .bytagname but as id is an attribute it is not accessible
Try:
(driver) findElement(By.xpath("//*[contains(local-name(), 'input') and contains(#name, 'qty')]")).sendKeys("100");
To answer the comment by #rrd: to be honest, I have no idea why OP uses ((Webdriver imgtags.get(i)). I don't know what that is. Normally, I just use driver.findElement[...]
Hoping that he knows what works in his framework :D
Selenium Xpath handling is not fully compliant and it does not always treat // as a synonym of descendant-or-self.
Instead try tweaking your code to use the following Xpath:
((Webdriver imgtags.get(i)).findElement(By.xpath("./descendant-or-self::input[#name='qty']")).sendKeys("100");
This will base your search off the currently selected WebElement and then look for any descendants that have a name attribute with a value of "qty".
I would also suggest storing your imgtags array as an array of WebElement e.g.
List<WebElement> imgtags = new ArrayList<>();
This is a much better idea than casting to WebDriver to be able to use .findElement(). This will cause you problems at some point in the future.

not able to find element using id in findelement in selenium

I am not able to find the element using "id" in selenium as the id is randomly changing in every session of execution so the same id i am not getting in next execution.
As there is no other unique property is there to identify the element.
code sample
You didn't specify a language so I'm going to give you Java. You can do this by using the CSS class or probably a better choice (because of likely uniqueness) is data-lynx-name.
By CSS class
driver.findElement(By.cssSelector("div.http-lynx-json-org-text-input"));
By attribute
driver.findElement(By.cssSelector("div[data-lynx-name='username']"));
You really should read the question that I duped this one to:
Find element by attribute
Also read more about CSS selectors,
http://www.w3.org/TR/selectors/#selectors
You can use XPath.
String xpath = //div[#data-lynx-name='usernameLabel'][text='User ID']/following-sibling::div[1]
The above XPath will will find the div tag containing text 'User ID' and finds the next div which is is the required textbox.
It seems that you can even use the attribute 'data-lynx-name' attribute of the textbox div tag directly.
String xpath = //div[#data-lynx-name='username']
Selenium
driver.findElement(By.xpath(xpath));

Enclose a list of tags (taghelper) by a parent tag

I need to achieve like below
<MyTagList>
<MyTag></MyTag>
<MyTag></MyTag>
</MyTagList>
When ever I use MyTag in design time, it need to be enclosed automaticaly by MyTagList or MyTag should error that it must be enclosed by MyTagList
You can't do this today at design time. You can however do it partially at runtime by utilizing TagHelperContext.Items. By using the Items property you can ensure that each tag is enclosed by a parent tag and throw if it's not. Insert an indicator into the Items bag in your parent element and verify that it exists in child elements.
As for supporting this in the future there are two issues open to add design time support:
https://github.com/aspnet/Razor/issues/255
https://github.com/aspnet/Razor/issues/474
Hope this helps!

How to find all WebElements on page by presence of id?

I know I can find element by id:
driver.findElement(By.xpath("//*[#id='some_id']"));
And I can find all elements with this id, but I want to find all elements with an id attribute. I'm looking for something like:
driver.findElements(By.xpath("//*[#id]"));
// or
driver.findElements(By.xpath("//*[#id='*']"));
// or
driver.findElements(By.xpath("//*[contains(#id)]"));
I'm using Java. Thanks!
UPD: The only solution for me is to get all elements by "//*", go through them and get their id attributes. Is there a way to get all attributes at once, something like "//*#A" from Java?
Attribute A of element where A contains 't'
//E[contains(#A,'t')]/#A
or
//E[contains(#A,'t')]#A
Attribute A of any element
//*/#A
or //*#A
so I use java too. So if you need to find all elements with id attribute you can simply use
driver.findElements(By.xpath(//*#id))
Hope this helps you.
ALso look here. Nice manual for xpath and css selectors
have you tried "//*[contains(#id, '')]"

How to select a specific table cell using HTML Agility Pack

I have to pull out particular fields from cells in an HTML table. Using Firebug I was able to get the exact XPath to the cells I need (unfortunately, the cells don't have an id tag). I thought I could use DocumentNode.SelectSingleNode and pass in that path, but it doesn't seem to be working right. What am I doing wrong? Or is there a better approach to this than how I am doing it? Unfortunately, I have no experience with XPath so this is turning out harder than I expected it to be. Here's what I have so far (I know the HTML is particuarly messy, but that's not in my control to change):
Dim page As New HtmlAgilityPack.HtmlDocument
Dim node As HtmlAgilityPack.HtmlNode
page.LoadHtml(fileContents)
node = page.DocumentNode.SelectSingleNode("/html/body/form/div[6]/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td[2]")
Much appreciated.
Firebug maybe fixed broken html tags.
If you want to pick and Html node,it is recommend use class or id.
For example:
//div[#class='content']//table//tr[1]/td[2]
shorten the path,and use class or id selector.
if the table has it's own id,you can use:
//table[#id='tableid']/tr[1]/td[2]
try it,you will find XPATH is interesting.