how do i click on the mage button
i tried with xpath and id below are the mentioned code that i had tried
driver.findElementById("btn_google").click();
// driver.findElementByName("Login with Google+").click();
//driver.findElementByXPath("//android.widget.ImageButton[#content-desc='Login with Google+',#resource-id,'btn_google']").click();
// driver.findElementByXPath("//android.widget.Button[contains(#resource-id,'btn_google') and #content-desc,'Login with Google+']").click();
// driver.findElementByXPath("//*[#class='android.widget.ImageButton' and #resource-id='btn_google']").click();
//driver.findElementByName("Login with Google+").click();;
WebElement element=driver.findElementByXPath("//*[#class='android.widget.ImageButton' and #resource-id='btn_google']");
TouchAction action = new TouchAction(driver);
action.longPress(element).release().perform();
//driver.findElement(By.xpath("//android.widget.ImageButton[#content-desct='Login with Google+']")).click();
// WebElement googlebutton= driver.findElementByXPath("//android.widget.ImageButton[#resource-id='com.zipgo.customer:id/btn_google']");
// googlebutton.click();
You can simply find the id of that imagebutton like:
googleImageButton=(ImageButton)findViewById(R.id.googleImageButton);
And now you can call a listener method for any operation, for eg:
googleImageButton.setOnClickListener(googleImageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//action
}
});)
try this
driver.findElementByXpath("//android.widget.ImageButton[#index='0']").click();
Related
Here is my code in my AddClassAdapter recylerview using firebase below on "onBindViewHolder":
holder.editBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
UserClasses userClasses = new UserClasses();
userClasses.openEditClassDialog();
}
});
And here is the "openEdiClassDialog" method in my main activity:
public void openEditClassDialog(){
UserClassEditDialog userClassEditDialog = new UserClassEditDialog();
userClassEditDialog.show(getSupportFragmentManager(),"user class dialog");
}
My problem is, If I clicked the edit button of an item in the recylerview adapter, this error shows in my logcat:
java.lang.IllegalStateException: FragmentManager has not been attached to a host. at androidx.fragment.app.FragmentManager.enqueueAction
At this moment, I am finding a solution to try, but I am expecting that if I clicked the edit button, a dialog will pop up.
enter image description here
This is what I want to create. A view renderable that allows the user to input text and upload.
Here is my current code, the button works well but EditText cannot invoke keyboard and input text. Is there some solution to this problem?
Thanks in advance.
private void addInfoCard(Node flag) {
Node infoCard = new Node();
infoCard.setParent(flag);
infoCard.setLocalPosition(new Vector3(0f, 0.25f, 0f));
ViewRenderable.builder()
.setView(this, R.layout.description_card)
.build()
.thenAccept(
(renderable) -> {
infoCard.setRenderable(renderable);
EditText mContent = (EditText) renderable.getView().findViewById(R.id.card_content);
Button mUploadBtn = (Button) renderable.getView().findViewById(R.id.card_upload);
mUploadBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "Content is"+mContent.getText().toString());
mUploadBtn.setVisibility(View.INVISIBLE);
}
});
})
.exceptionally(
throwable -> {
Toast toast = Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});
}
I have the following problem:
My method opens a JDialog with a bunch of buttons (only one in example code). I want to click a button and thereby choose an ImageIcon for my method to return. But the Method does not wait for me to click a button. It opens the window and then returns an empty ImageIcon.
public class Kartenauswahl {
ImageIcon bandit;
public ImageIcon auswahlfenster() {
int bwidth = new Integer(150);
int bheight = new Integer(225);
bandit = new ImageIcon("cover/Bandit.jpe");
bandit.setImage(bandit.getImage().getScaledInstance(bwidth,bheight,Image.SCALE_DEFAULT));
final JDialog kartenwahl = new JDialog();
kartenwahl.setTitle("Kartenwahl");
kartenwahl.setSize(1500,1000);
kartenwahl.setVisible(true);
kartenwahl.setLayout(new FlowLayout());
ImageIcon returnicon= new ImageIcon();
final JButton b1 = new JButton(); //just to get the Icon out of the void loop
JButton B1 = new JButton(bandit); //this is going to be the button I want to click to choose the ImageIcon which is returned
B1.setContentAreaFilled(false);
B1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
b1.setIcon(bandit);
kartenwahl.dispose();
}
});
kartenwahl.add(B1);
returnicon = (ImageIcon) b1.getIcon();
return returnicon;
}
}
Question: can I bind the return statement to a condition? Like "only return after I clicked that Button B1"?
Hi sorry for the long wait. I have written an custom JDialog that should work for you.
public class CustomDialog extends JDialog {
JButton[] buttons;
ImageIcon selectedImageIcon;
public CustomDialog() {
setSize(500, 500);
setLayout(new GridLayout(4, 6));
ActionListener actionListener = new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
selectedImageIcon = ((ImageIcon) ((JButton) e.getSource()).getIcon());
dispose();
}
};
buttons = new JButton[24];
for(int i = 0; i < 24; i++) {
buttons[i] = new JButton(new ImageIcon("path_to_your_image_file"));
buttons[i].addActionListener(actionListener);
add(buttons[i]);
}
setVisible(true);
}
public ImageIcon getSelectedImageIcon() {
return selectedImageIcon;
}
}
The initial size is not that important the GridLayout is. you mentioned that you would need 24 buttons so I created an grid with 4 rows and 6 columns.
Then I create the buttons in a loop and adding the same Listener to set the selection icon with the icon of the pressed button. Afterwards I dispose the screen triggering an windowClosed event.
You could simply create this Dialog from your main class and wait for the response like so:
public class main {
public static void main(String[] args) {
CustomDialog customDialog = new CustomDialog();
customDialog.addWindowListener(new WindowAdapter() {
#Override
public void windowClosed(WindowEvent e) {
ImageIcon icon = customDialog.getSelectedImageIcon();
//do something with your icon
}
});
}
}
Don't forget to mark this answer as correct if it fixes your problem.
Have a good one!
I want to get the button click event in each row. How to get that ?. I tried this link and its working if there is only one button in each row. But in my case, there are more than one button in each row. 10,20 and 11,21 are my buttons.
in RowManager class from the above link, i added the following code -
button = new ButtonField("1" + index, ButtonField.CONSUME_CLICK);
button.setCookie(new Integer(index));
button.setFont(textFont);
add(button);
button1 = new ButtonField("2" + index, ButtonField.CONSUME_CLICK);
button1.setCookie(new Integer(index));
button1.setFont(textFont);
add(button1);
Now on StackScreen class, public void fieldChanged(Field field, int context), How i get the name of the clicked buttons ?
Solved By My self -
public static int v=0;
button = new ButtonField("1" + index, ButtonField.CONSUME_CLICK);
button.setCookie(new Integer(v+1)); //set cookie
button.setFont(textFont);
add(button);
v=v+1; //increment the value of v
button1 = new ButtonField("2" + index, ButtonField.CONSUME_CLICK);
button1.setCookie(new Integer(v+1));
button1.setFont(textFont);
add(button1);
v=v+1;
and -
public void setChangeListener(FieldChangeListener listener) {
// only the button field supports change listeners
button.setChangeListener(listener);
button1.setChangeListener(listener);
}
Then on StackScreen class -
public void fieldChanged(Field field, int context) {
Object f=field.getCookie();
Dialog.alert("Button " +f);
}
I want to run some Java code when the user clicks on this ToolbarButtonField in my BlackBerry app. I have the following code which is not working. Please tell me where I am wrong.
butHome = new ToolbarButtonField(new StringProvider("Home"));
butHome.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
System.out.println("Clicked...");
}
});
You can use:
ToolbarButtonField#invoke
Performs an action when this
ToolbarButtonField is clicked on if
Command has been set. A click is
defined as the following sequence of
touch events: TouchEvent.DOWN,
TouchEvent.CLICK, TouchEvent.UNCLICK
and TouchEvent.UP.
You're going to have to use that in conjuction with the Command framework. If that's not desirable, override ToolbarButtonField#touchEvent for a TouchEvent.UNCLICK event to execute the desired code.
public boolean touchEvent(TouchEvent message) {
if ( message.geEvent() == TouchEvent.UNCLICK ) {
// do what I want.
}
}
Try this:
butHome = new ToolbarButtonField(new StringProvider("Home")) {
protected boolean navigationClick(int status, int time) {
System.out.println("Clicked...");
return true;
}
});