Does someone know why xpath does not work? When I use "LG", not template with %s everything works fine.
public static void check(){
String path="\"//span[#class='schema-filter__checkbox-text' and text()='%s']\"";
String way = String.format(path, "LG");
driver.findElement(By.xpath(way); - not working
}
The method didnt work because I set incorrect property.
public class Page{
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\....\\drivers\\geckodriver.exe");
driver=new FirefoxDriver(); - I set WebDriver driver=new FirefoxDriver() in the beginning.
.....
.....
}
and also '\' from the template should be removed.
public static void f(){
String path="//span[#class='schema-filter__checkbox-text' and text()='%s']";
String way = String.format(path, "LG");
System.out.println(driver.findElement(By.xpath(way)).getText());
}
Related
In my Android app I use AAC.
Here my activity:
public class AddTraderActivity extends AppCompatActivity {
AddTraderViewModel addTraderViewModel;
private static final String TAG = AddTraderActivity.class.getName();
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AddTraderActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.add_trader_activity);
binding.setHandler(this);
init();
}
private void init() {
ViewModelProvider viewViewModelProvider = ViewModelProviders.of(this);
addTraderViewModel = viewViewModelProvider.get(AddTraderViewModel.class);
Observer<String> () {
#Override
public void onChanged (String message){
Debug.d(TAG, "onChanged: message = " + message);
Toast.makeText(AddTraderActivity.this, message, Toast.LENGTH_LONG).show();
}
});
}
public void onClickStart() {
EditText baseEditText = findViewById(R.id.baseEditText);
EditText quoteEditText = findViewById(R.id.quoteEditText);
addTraderViewModel.doClickStart(baseEditText.getText().toString(), quoteEditText.getText().toString());
}
}
Here my ViewModel:
public class AddTraderViewModel extends AndroidViewModel {
private MutableLiveData<String> messageLiveData = new MutableLiveData<>();
private static final String TAG = AddTraderViewModel.class.getName();
public AddTraderViewModel(#NonNull Application application) {
super(application);
}
public void doClickStart(String base, String quote) {
Debug.d(TAG, "doClickStart: ");
if (base.trim().isEmpty() || quote.trim().isEmpty()) {
String message = getApplication().getApplicationContext().getString(R.string.please_input_all_fields);
messageLiveData.setValue(message);
return;
}
}
public LiveData<String> getMessageLiveData() {
return messageLiveData;
}
}
So when I click on button on Activity call method onClickStart()
If any fields is empty the show toast. In the activity call method:
onChanged (String message)
Nice. It's work fine.
But the problem is, when I rotate the device in the activity method onChanged(String message) is called AGAIN and as result show toast. This happened on every rotation.
Why?
This is the expected behaviour. If you want to avoid this you must set message = "" and keep an empty check before showing the toast.
A better way to use it is something like Event Wrapper or SingleLiveEvent
Highly recommend you to read this article. This explains why you are facing this and what are your options in detail.
I am using p{L} to accept chinese alphabet in our code, i tested this in eclipse and the system showed success result whereas when the same was used in Oracle Jdeveloper, system is throwing a failure. This is the code snippet, i am using.
Please provide me an answer.
public static final String VALID_CHARACTER_PATTERN = "[\\p{L}0-9_*]*";
public static final boolean hasRestrictedChars(String suspectedString) {
return !suspectedString.matches(VALID_CHARACTER_PATTERN);
}
public static void main(String[] args) {
boolean check = hasRestrictedChars("你好");
if (check)
System.out.println("InValid String");
else {
System.out.println("Perfect");
}
}
I want to add an item to the start menu to display a list of applications that the user can launch. Kind of like a custom menu. I got the WIN API code pack and understand that I can use a jump list for the popup menu part. Not sure how I can pin something to the start menu though. I'm looking for something along the lines of what IE displays.
Was able to accomplish this using Shell32 library.
public static class VerbNames{
public static string PinToStartMenu = "Pin to Start Men&u";
public static string UnpinFromStartMenu = "Unpin from Start Men&u";
public static string PinToTaskbar = "Pin to Tas&kbar";
public static string UnpinFromTaskbar = "Unpin from Tas&kbar";
}
public static class DesktopUtil {
public static void PinItemToStartMenu(string itemPath, string itemName) {
DoItemVerb(itemPath, itemName, VerbNames.PinToStartMenu);
}
public static void UnpinItemFromStartMenu(string itemPath, string itemName) {
DoItemVerb(itemPath, itemName, VerbNames.UnpinFromStartMenu);
}
public static void PinItemToTaskbar(string itemPath, string itemName) {
DoItemVerb(itemPath, itemName, VerbNames.PinToTaskbar);
}
public static void UnpinItemFromTaskbar(string itemPath, string itemName) {
DoItemVerb(itemPath, itemName, VerbNames.UnpinFromTaskbar);
}
private static void DoItemVerb(string itemPath, string itemName, string verb) {
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder folder = shell.NameSpace(itemPath);
Shell32.FolderItem item = folder.ParseName(itemName);
DoItemVerb(item, verb);
}
private static void DoItemVerb(Shell32.FolderItem item, string verbToDo) {
Shell32.FolderItemVerbs verbs = item.Verbs();
foreach (Shell32.FolderItemVerb verb in verbs) {
if (verb.Name.Equals(verbToDo)) {
verb.DoIt();
}
}
}
}
I'm investigating the best way to write a rich text editor in JavaFX - don't mention the HTMLEditor to me: we've spent literally months hacking at it and I could write reams about why it isn't suitable for our purposes! Choice at the moment is to extend AnchorPane and do all of the layout, navigation etc. from scratch or to extend TextInputArea, which looks as though it would help. Anyone have their own implementation of that or would like to propose a minimal implementation?
FWIW here's a scrap from me:
public class TryPain3 extends TextInputControl {
private AnchorPane rootNode = new AnchorPane();
public TryPain3() {
super(new Content() {
private String text = "";
#Override
public String get(int i, int i1) {
return text.substring(i, i1);
}
#Override
public void insert(int i, String string, boolean bln) {
}
#Override
public void delete(int i, int i1, boolean bln) {
}
#Override
public int length() {
return text.length();
}
#Override
public String get() {
return text;
}
#Override
public void addListener(ChangeListener<? super String> cl) {
}
#Override
public void removeListener(ChangeListener<? super String> cl) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
#Override
public String getValue() {
return text;
}
#Override
public void addListener(InvalidationListener il) {
}
#Override
public void removeListener(InvalidationListener il) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
setEditable(true);
Text text1 = new Text("fred was here");
text1.setFont(Font.font("Tahoma", FontWeight.NORMAL, 18));
text1.setTextAlignment(TextAlignment.LEFT);
text1.setFontSmoothingType(FontSmoothingType.LCD);
rootNode.getChildren().add(text1);
setSkin(new TP3Skin(this, rootNode));
}
class TP3Skin implements Skin<TryPain3> {
TryPain3 tp;
Node root;
public TP3Skin(TryPain3 tp, Node root) {
this.tp = tp;
this.root = root;
}
#Override
public TryPain3 getSkinnable() {
return tp;
}
#Override
public Node getNode() {
return root;
}
#Override
public void dispose() {
tp = null;
rootNode = null;
}
}
}
It looks as though the skin is not optional.
Questions I'd like to find out are things like:
how is the UI supposed to be drawn - I'm quite happy to code it from scratch but how to get benefit of calls to forward() as an example
should the UI creation be done in the Skin?
whether the base class deals with things like where to put the cursor if you click on a bit of text
I'm sure other questions will arise from this.
You may want to try next JavaFX 8.0 control TextFlow, which allows aggregation of various text styles. See examples here: https://wikis.oracle.com/display/OpenJDK/Rich+Text+API+Samples
JavaFX 8 is part of JDK8. So you can download developers build here http://jdk8.java.net/download.html and it will include JavaFX and new TextFlow control.
I'm new to PostSharp and investigating it's use for our project. I'm trying to apply OnMethodBoundaryAspect on an abstract method and getting the following error: http://screencast.com/t/1LyzIz2M
Able to execute the aspect just fine with regular and virtual methods, am I missing anything or is it not possible w/ abstract members?
Here's my simple aspect:
[Serializable]
public sealed class TraceAttribute : OnMethodBoundaryAspect
{
protected string _strMethodName;
protected static readonly Stopwatch _sw = new Stopwatch();
public TraceAttribute(string pMethodName)
{
_strMethodName = pMethodName;
}
public override void OnEntry(MethodExecutionArgs args)
{
_sw.Start();
string strMsg = string.Format(">> Entering {0}.{1}", args.Method.DeclaringType.Name, args.Method);
Debug.Print(strMsg);
}
public override void OnExit(MethodExecutionArgs args)
{
_sw.Stop();
string strMsg = string.Format("<< Leaving {0}.{1} - EXECTIME: {2} ms", args.Method.DeclaringType.Name,
args.Method, _sw.ElapsedMilliseconds);
Debug.Print(strMsg);
_sw.Reset();
}
}