I have tried to click the button using all techniques. But I am unable to click it - html

<button class="md-icon-button md-button md-ink-ripple"
type="button" ng-transclude="" ng-click="hide()">
<i class="fa fa-remove ng-scope"></i>
</button>
StepDefinition Code:
#And("^Check whether the Alert message display properly$")
public void alert_msg_display() throws Throwable {
WebElement x= driver.findElement(By.xpath("//button[#data-hover='LOGIN NOW']")); // Path of login button
actionClick(driver, x); // To click login button
WebElement y= driver.findElement(By.xpath("//div[#class='md-dialog-content ng-binding']")); // Path of Alert message text
String a = y.getText();
WebElement z= driver.findElement(By.xpath("//i[#class='fa fa-remove ng-scope']")); // Path of close button of alert popup
waitClick(driver, z); // To wait until close button display
actionClick(driver, z); // Click on close (Note:This operation get FAILED)
String a1 = "Please Enter Branch Id";
driver.findElement(By.xpath("//input[#ng-model='Branchid']")).sendKeys("HO");
actionClick(driver, x);
String b = y.getText();
waitClick(driver, z);
actionClick(driver, z);;
String b1 = "Please Enter Username (Email Id)";
if (a.equals(a1) && b.equals(b1))
test.log(LogStatus.PASS, "Test Case ID: LOG_006 to LOG_010 - Pass");
else
test.log(LogStatus.FAIL, "Test Case ID: LOG_006 to LOG_010 - Fail");
}
Runner File
public void actionClick(WebDriver driver, WebElement a) {
Actions action = new Actions(driver);
action.moveToElement(a).click().build().perform();
}
public void waitClick(WebDriver driver, WebElement a) {
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOf(a));
}
I have tried to click the button using .click method, Actions method, JSExecutor method and also used Wait... But I am unable to click the button. Please, drop your valuable comments. Thanks in advance...

It should operate on pressing the ESCAPE keys. Please try below:
The following 2 ways could work:
Getting the element locator of that image -> Send Escape to the element.
WebElement loginimg = driver.findElement(By.id("AlertX")); loginimg.sendKeys(Keys.ESCAPE);
Or
You can press Escape key by Java Robot class as below:
import java.awt.Robot; import java.awt.event.KeyEvent;
Robot r = new Robot(); r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);

from my observations, it is clear that it is not an normal browser alert (if it is, then we can't inspect the elements in it) , so the selenium alert related codes won't work here (like driver.switchToAlert() will throw an No such alert).
Try to click using the following code snippet, it may works
WebElement z= driver.findElement(By.xpath("//button[#class='md-icon-button md-button md-ink-ripple']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", z);

Related

Blazor - iterate through EditForm

I am building a (static) website in Blazor.wasm where the users upload some number of files. My intention is then (after all the files have passed some basic checks) to iteratively present a set of fields which the users are asked to complete. Only after they have submitted all the [Required] information and press submit will the next form show up.
I have included a minimal example below.
if (valid_files == numFiles)
{
for (int counter = 0; counter < num_files; counter++)
{
paramList.Add(new ParamsForm { });
<EditForm Model="#paramList[counter]" OnValidSubmit="#SingleSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
Camera type <br>
<InputText id="cameratype" #bind-Value="#paramList[counter].CameraType" />
</p>
<button type="submit">Submit</button>
</EditForm>
}
<button #onclick="HandleValidSubmit">Upload Data </button>
}
The expected behaviour is that on each iteration, a frech instance of the onbject ParamsForm is added to the list. We then create a form based of that instance and wait for the user to complete the form. Once they press the Submit button the next stage of the for loop begins. Once all the data have been submitted and the for loop is completed, the Upload data button should appear and the users are invited to submit all their data to the server.
Instead, none of the code inside the EditForm ... section is being completed. I.e. - I see no popping up of text boxes, and any code that I put in there (for example #Console.WriteLine("This should show up) does not seem to be executed. The Upload data button does not appear and instead an error is thrown complaining that the index is out of range, which is weird because after the code at the top of the for loop there are no longer any elements being accessed by an index.
I am quite new to interacting between c# and HTML, so I think I can appreciate why what I have shouldn't work, but I don't know how I can go about writing something that will work.
Any advice would be gratefully recieved.
The ways of Blazor are a bit mysterious to me, too-- it takes a while to adjust! I do know that Blazor has an OnAfterRender event, which makes me think that it might not like to have user input in a loop like that. Or it may be that it's enumerating if (valid_files == numFiles) as false because those variables aren't initialized yet when the markup first renders.
I'd try two things:
(1) Throw StateHasChanged() at the end of your loop or after the code that sets valid_files and numFiles and see if that does anything you like.
(2) Probably this anyway: instead of looping in the markup, I'd build the entire List<ParamsForm> paramsList in the FileInput's event handler instead, move the counter to the code block, and add counter++ to the end of the SingleSubmit() method.
It's 5:00 am here, just got up to get a snack and going back to bed. Let me know if things still don't fly, and I'll try a more complete example tomorrow. :D
I don't have much information about your class, where you are getting your file list from, and so on. I recommend passing complete objects rather than individual properties. For example, I'd rather have IBrowserFile File {get; set;} in my ParamsForm class than say string FileName. That way, if I decide-- oh, I want to get this or that property-- it's already there.
Anyway, hope something in here might be useful:
#if (CurrentForm is not null)
{
<EditForm Model="CurrentForm" OnValidSubmit="#SingleSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
Camera type <br>
<InputText id="cameratype" #bind-Value="CurrentForm.CameraType" />
</p>
<button type="submit">Submit</button>
</EditForm>
#if (IsComplete) // Don't show upload button until you're done
{
<button #onclick="DoUploads">Upload Data </button>
}
#DisplayMessage
}
#code {
class ParamsForm { public string FileName; public string CameraType; } // Just a placeholder
List<ParamsForm> ParamsList = new List<ParamsForm>();
ParamsForm CurrentForm { get; set; }
int counter = 0;
List<string> FileNames;
bool IsComplete = false;
string DisplayMessage = "";
void InitializeForms()
{
// I don't know your class, so just an example
foreach (var item in FileNames)
{
bool IsValid = false;
// check file validity
if (IsValid) ParamsList.Add(new ParamsForm() { FileName = item });
}
if(ParamsList.Count > 0)
CurrentForm = ParamsList[0];
}
void SingleSubmit()
{
// Do stuff with CurrentForm
if (++counter >= ParamsList.Count) IsComplete = true;
else CurrentForm = ParamsList[counter];
}
async Task DoUploads()
{
// Do stuff with your ParamsList
int UploadCounter = 0;
foreach (ParamsForm item in ParamsList){
DisplayMessage = "Uploading " + UploadCounter + " of " + ParamsList.Count;
StateHasChanged();
// Do the Upload;
}
DisplayMessage = "Finished.";
}
}

Eclipse FormEditor button as page title

I implemented my custom FormEditor. Now I want to let user create new FormPages (a.k.a. tabs) in this editor like it is made e.g. in Chrome tabs. How to insert a "new tab" button near the titles of existing FormPages?
Thank you in advance!
UPD:
I added a FormPage with title "+" and insert new page in listener to PageChangedEvent.
You can add actions to the toolbar at the top right of a FormPage like this:
ScrolledForm form = managedForm.getForm();
IToolBarManager manager = form.getToolBarManager();
Action myAction = new Action("My Action") {
public void run() {
// TODO your action
}
};
myAction.setToolTipText("tooltip text");
myAction.setImageDescriptor(action image descriptor);
manager.add(myAction);

getting no such element exception message

i am using eclipse juno and testing the application actitime,which has a check box in login page "keepLoggedInCheckBox"
The HTML source of it,
<input type="checkbox" title="Do not select if this computer is shared"
id="keepLoggedInCheckBox" value="on" name="remember">
I am trying locate the check box "keepLoggedInCheckBox" by using ,
WebElement check = driver.findElement(By.id("keepLoggedInCheckBox"));
But getting this error,
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Unable to locate element:
{"method":"id","selector":"keepLoggedInCheckBox"}
i tried with xpath (//input[#id='keepLoggedInCheckBox']) ,also getting same error.
please help me, to solve this.
I have faced the same problem. The DOM looses the reference to the element in question. It can either be StaleStateReferenceException or NoSuchElementException. There are two ways to deal with the situation.
(Though my solution is in Java. The underlying concept is the same. )
By using the the following method, you can try clicking an element. If exception is thrown then catch the exception and try to click again until the element is present:
public boolean retryingFindClick(By by) {
boolean result = false;
int attempts = 0;
while(attempts < 2) {
try {
Actions action = new Actions(driver);
WebElement userClick = wait.until(ExpectedConditions.presenceOfElementLocated(by));
action.moveToElement(userClick).click().build().perform();
driver.findElement(by).click();
result = true;
break;
} catch(StaleElementReferenceException e) {
System.out.println("StaleElementReferenceException");
}
catch(NoSuchElementException e) {
System.out.println("No Such Element Found");
}
attempts++;
}
return result;
}
Please try this. I have added implicitlyWait which will allow your DOM content to load.
Note: Please replace Your URL with the exact URL.
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("Your URL");
driver.findElement(By.xpath("//*[#id='keepLoggedInCheckBox']")).click();

Creating html buttons in code, for table. How to handle server callbacks?

I'm currently working on a project and got stuck. I have a Literal control, placed in my .aspx page and I use a stringbuilder like this to populate it with data :
public string CreateNewEntry(String garageName, String garageType,String garageAdress, String garagePhone, String garageId)
{
StringBuilder sb = new StringBuilder();
sb.Append(#"<tr class=""odd"">");
sb.Append(#"<td class=""v-middle"">");
sb.Append(garageName);
sb.Append(#"</td>");
sb.Append(#"<td class=""v-middle"">");
sb.Append(garageType);
sb.Append(#"</td>");
sb.Append(#"<td class=""v-middle"">");
sb.Append(garageAdress);
sb.Append(#"</td>");
sb.Append(#"<td class=""v-middle"">");
sb.Append(garagePhone);
sb.Append(#"</td>");
sb.Append(#"<td class="""">");
sb.Append(#"<a href=""#"" class=""btn btn-sm btn-icon btn-success"" id=""");
sb.Append("edit"+garageId);
sb.Append(#""" name=""");
sb.Append("edit"+garageId);
sb.Append(#"""runat=""server"" OnServerClick=""processRowButtonClick""><i class=""fa fa-edit""></i></a>");
sb.Append(#"<a href=""#"" class=""btn btn-sm btn-icon btn-danger"" id=""");
sb.Append("delete"+garageId);
sb.Append(#""" name=""");
sb.Append("delete"+garageId);
sb.Append(#"""runat=""server"" OnServerClick=""processRowButtonClick""><i class=""fa fa-ban fa-indent""></i></a></td></tr>");
return sb.ToString();
}
I then run a SQL query, to gather the data and loop trough it with a foreach loop adding all table elements dynamically to the Literal controller.
public void garageViewPopulator()
{
serviceDatabaseDataContext dbQuery = new serviceDatabaseDataContext();
var query = (from GarageDetails in dbQuery.GarageDetails
select GarageDetails);
String _constructorString = "";
NewListEntry tableEntry = new NewListEntry();
foreach (GarageDetail item in query)
{
//Creating new HTML code from the class above
_constructorString += tableEntry.CreateNewEntry(item.garageName.ToString(), item.garageType.ToString(), item.garageAdress.ToString(), item.garagePhone.ToString(), item.garageId.ToString());
}
// My litteral
garageListHolder.Text = _constructorString;
}
I then have a :
protected void processRowButtonClick (object sender, EventArgs e)
{
//Retrieve what button id was pressed, and exec action.
}
In my code-behind file. I assumed this would get called when a user pressed a button in my generated table shown under.
Two questions, is it possible to do it this way? Will the code register the buttons as clickable when i generate them from code? Because right now, clicking them does not execute the current processRowButtonClick function in the code behind.
Secondly, If this is possible, how would I get the name / id of the button pressed? Does anybody have any input?
(It may be easier methods of achieving what I'm trying to do, so I'l be happy to receive information about better solutions as well).

LinkButton not accessing EventArg

I am using c#.net.
I am trying to create a LinkButton within the code-behind, when I debug my code I recieve no errors, however its not accessing the EventArg attached to the button, it does however refresh the page. What am I doing wrong?
Button Code
LinkButton myLinkButton = new LinkButton();
myLinkButton.ID = appointment.appID.ToString();
myLinkButton.CommandArgument = appointment.appID.ToString();
myLinkButton.Command += new CommandEventHandler(ViewClick);
myLinkButton.CommandName = appointment.appID.ToString();
myLinkButton.Text = appointment.contactName
Used to style button
string divLook = "height:" + divHeight + "em";
Button is then added to a panel
Panel p = new Panel();
p.Style.Add("linkStyle", divLook);
p.CssClass = "standardLink";
p.Controls.Add(myLinkButton);
dataCell.Controls.Add(p);
protected void ViewClick(object sender, CommandEventArgs e)
{
var appointmentId = Convert.ToInt32(e.CommandArgument);
Debug.Write("Are you even getting in here");
}
Thanks in advance for any help.
Clare
Everything looks legit. I would recommend viewing the source of the generated page and looking at the ID that the link button is getting. It may be duped on the page.