I've executed my code in selenium-java and i need a value of Identifiers(2nd line, not the 4th one) from .XML which is opened in MS edge browser.
My XML:
<Application Type="ABCD">
<Identifier>18753</Identifier>
<SalesChannel SalesChannelType="PQRS" SalesChannelSegment="XYZ">
<Identifier>AB1234</Identifier>
Can anyone help me with the code to get a values(18753) which is between Identifier 2nd line.
Note: I've a code which is working fine for chrome & FF, but bot able to work for MSedge:
Assert.assertTrue(driver.getPageSource().contains("Identifier"));
String xml = driver.getPageSource();
String appID = xml.split("<Identifier>")[0].split("</Identifier>")[1];
I think there's a mistake in your split function. The right code should be like this:
String appID = xml.split("</Identifier>")[0].split("<Identifier>")[1];
Sample code:
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
public class Edgeauto {
public static void main(String[] args) {
System.setProperty("webdriver.edge.driver", "your_path_of_webdriver\\msedgedriver.exe");
EdgeOptions edgeOptions = new EdgeOptions();
WebDriver driver = new EdgeDriver(edgeOptions);
driver.get("http://xxx.xml");
Assert.assertTrue(driver.getPageSource().contains("Identifier"));
String xml = driver.getPageSource();
String appID = xml.split("</Identifier>")[0].split("<Identifier>")[1];
System.out.println(appID);
}
}
Result:
Related
The console does not respond to this code. Here I tried to use stdout.write(), instead of print().
'For your convenience, I use Microsoft VS code.'
import 'dart:io';
void main() {
stdout.write('Enter your name:');
String name = stdin.readLineSync(); //Read name
stdout.write('Enter your age:');
int age = int.parse(stdin.readLineSync()); //Read age as int
stdout.write('You are $age and your name is $name');
}
The problem is that the vs code console doesn't allow input.
You need to create a launch config and set console to terminal.
I am currently working on a project to manipulate Docx file with the Apache POI project. I have used the api to remove text from a run inside of a text box, but cannot figure out how to remove a paragraph inside a text box. I assume that I need to use the class CTP to obtain the paragraph object to remove. Any examples or suggestion would be greatly appreciated.
In Replace text in text box of docx by using Apache POI I have shown how to replace text in Word text-box-contents. The approach is getting a list of XML text run elements from the XPath .//*/w:txbxContent/w:p/w:r using a XmlCursor which selects that path from /word/document.xml.
The same of course can be done using the path .//*/w:txbxContent/w:p, which gets the text paragraphs in text-box-contents. Having those low level paragraph XML, we can converting them into XWPFParagraphs to get the plain text out of them. Then, if the plain text contains some criterion, we can simply removing the paragraph's XML.
Source:
Code:
import java.io.FileOutputStream;
import java.io.FileInputStream;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlCursor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import java.util.List;
import java.util.ArrayList;
public class WordRemoveParagraphInTextBox {
public static void main(String[] args) throws Exception {
XWPFDocument document = new XWPFDocument(new FileInputStream("WordRemoveParagraphInTextBox.docx"));
for (XWPFParagraph paragraph : document.getParagraphs()) {
XmlCursor cursor = paragraph.getCTP().newCursor();
cursor.selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//*/w:txbxContent/w:p");
List<XmlObject> ctpsintxtbx = new ArrayList<XmlObject>();
while(cursor.hasNextSelection()) {
cursor.toNextSelection();
XmlObject obj = cursor.getObject();
ctpsintxtbx.add(obj);
}
for (XmlObject obj : ctpsintxtbx) {
CTP ctp = CTP.Factory.parse(obj.xmlText());
//CTP ctp = CTP.Factory.parse(obj.newInputStream());
XWPFParagraph bufferparagraph = new XWPFParagraph(ctp, document);
String text = bufferparagraph.getText();
if (text != null && text.contains("remove")) {
obj.newCursor().removeXml();
}
}
}
FileOutputStream out = new FileOutputStream("WordRemoveParagraphInTextBoxNew.docx");
document.write(out);
out.close();
document.close();
}
}
Result:
Can someone please help me here, below is the code:
package student.profile.picture;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import static io.restassured.RestAssured.given;
import org.testng.annotations.Test;
public class GetProfilePicture {
#Test
void Fetch()
{
RestAssured.baseURI="http://localhost:5100"; // giving base URI
Response res=given().
header("tenantId","Augusta-PT").
when().
get("/ProfilePicture").
then().assertThat().statusCode(200).extract().response();
String responsestring=res.asString();
System.out.println(responsestring);
/*JsonPath js = new JsonPath(responsestring);
String FileContentType = js.get("fileContentType");
String ExpectedFilecontenttype = "image/png";
System.out.println(FileContentType);
Assert.assertEquals(FileContentType, ExpectedFilecontenttype); */
}
}
It does not show any error, it is a simple get method to show response, nothing shows up in console.
Any help please?
It is recommended to break up your statement in two parts,
First, get the response,
RestAssured.baseURI = "http://localhost:5100";
Response res = given()
.header("tenantId","Augusta-PT")
.when()
.get("/ProfilePicture");
And second part to assert,
res.then()
.assertThat()
.statusCode(200);
System.out.println(res.asString());
This will solve your issue and you should be able to get the response in console.
I have to create an mscons export of energy values. I created a bit of code from some examples I found, but now I stuck. MSCONS needs an UNB and an UNH header.
I can add the UNB header to the UNEdifactInterchange41 object, but I don't find a method to attach the UNH header.
Here's my code so far:
import org.milyn.SmooksException;
import org.milyn.edi.unedifact.d16b.D16BInterchangeFactory;
import org.milyn.edi.unedifact.d16b.MSCONS.*;
import org.milyn.smooks.edi.unedifact.model.r41.*;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.StringWriter;
import org.milyn.smooks.edi.unedifact.model.r41.types.MessageIdentifier;
import org.milyn.smooks.edi.unedifact.model.r41.types.Party;
import org.milyn.smooks.edi.unedifact.model.r41.types.SyntaxIdentifier;
public class EDI {
public static void main(String[] args) throws IOException, SAXException, SmooksException {
D16BInterchangeFactory factory = D16BInterchangeFactory.getInstance();
UNEdifactInterchange41 edi = new UNEdifactInterchange41();
Mscons mscons = new Mscons();
/*UNB*/
UNB41 unb = new UNB41();
unb.setSender(null);
Party sender = new Party();
sender.setInternalId(getSenderInternalId());
sender.setCodeQualifier(getSenderCodeQualifier());
sender.setId(getSenderId());
SyntaxIdentifier si=new SyntaxIdentifier();
si.setVersionNum("3");
si.setId("UNOC");
unb.setSyntaxIdentifier(si);
unb.setSender(sender);
edi.setInterchangeHeader(unb);
/*UNH*/
UNH41 unh = new UNH41();
MessageIdentifier mi=new MessageIdentifier();
mi.setTypeSubFunctionId("MSCONS");
mi.setControllingAgencyCode("UN");
mi.setAssociationAssignedCode("2.2h");
String refno=createRefNo();
unh.setMessageIdentifier(mi);
/* How to attach UNH? */
}
}
Sounds like you got it almost right, you need to attach the UNH to message and not the opposite:
mi.setMessageIdentifier(unh);
You have an example there if you need:
https://github.com/ClaudePlos/VOrders/blob/master/src/main/java/pl/vo/integration/edifact/EdifactExportPricat.java
There is a problem about usage of Flaticon. I have imported .ttf file that I have downloaded and I have visual of FontIcon font style in my project. Here is a example code of implementation flaticon fonts.
public static class FlatIcon
{
public static string FlaticonTwitterLogoSilhoutte = "\f100";
public static string FlaticonGooglePlus = "\f101";
public static string FlaticonFacebookLogo = "\f102";
public static string FlaticonTick = "\f103";
}
And here is the code that I am trying to visualize Icon.
FacebookIcon.Text = $"{FlatIcon.FlaticonFacebookLogo}";
I am not able to get output of what I expect and I am not able to understand why, can you help me with this issue?