I've the problem. I want to get some texts from alert that created by yii2 when the input text was blank. So here is test case on codeception (functional):
public function submitEmptyForm(\FunctionalTester $I)
{
$I->submitForm('#contact-form', []);
$I->expectTo('see validations errors');
$I->see('Contact', 'h1');
$I->see('Name cannot be blank');
$I->see('Email cannot be blank');
$I->see('Subject cannot be blank');
$I->see('Body cannot be blank');
$I->see('The verification code is incorrect');
}
And I ran that code, but I found the error in line:
$I->see('Name cannot be blank');
When I spec the code with inspect element, Here's the alert that I got:
<p class="help-block help-block-error">Name cannot be blank.</p>
How can I get the alert text when the doesn't have name or id ? I read "How to call element in codeception" in codeception.com, you should be called by name or id.
Make the text match exactly so add the full stop to the end and specify the class like below and it should find it.
$I->see('Name cannot be blank.', '.help-block');
Related
cy.xpath("(//[local-name()='svg']//[name()='g' and #data-z-index='8'])[1]//*[name()='text']").wait(300)
.trigger('mouseover', { force: true }).then(($text1) => {
var textValue2 = $text1.text()
cy.log(textValue2)
})
This is code I'm using triggering to perform mouseover to get the text
facing error not finding the element showing "Timed out retrying after 4000ms: Expected to find element: (//[local-name()='svg']//[name()='g' and #data-z-index='8'])[1]//*[name()='text'], but never found it."
Note: But the xpath is correct, If I manually hover then retrieve the text.
Use trigger('mouseenter') it should works
What do I have:
Laravel 5.5
Laravel Dusk 2.0.14
How can I test (assert) that browser tooltip
was shown, when I'm trying to submit a form without filling required field?
What I've tried:
$browser
->assertSee('Please fill out this field');
But it didn't work.
You can get the message with JavaScript:
$message = $browser->script("return document.querySelector('input[name=foo]').validationMessage")[0];
$this->assertEquals('Please fill out this field.', $message);
Note that the message will always be set as long as the input's value is invalid. This assertion also works before you press the submit button.
I am using Selenium Webdriver with TestNG.
I have kept the details of all the locators in a separate properties file.
When I try to reference the locators in my Java Code, I am getting the following error in the logs
InvalidSelectorError: Unable to locate an element with the xpath
expression "/html/body/div[1]/nav/div/div[2]/ul/li[6]/a/b" because of
the following error: TypeError: The expression cannot be converted to
return the specified type.
Please find the code below :
#Test(priority=1)
public void testLoginOnFirstPage() {
try {
log.debug("Test#1 - Login on the Home page ");
driver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
loginButtonHomePage=By.xpath(prop.getProperty("login.button.homePage.xpath"));
driver.findElement(loginButtonHomePage).click();
Assert.assertTrue(true,"Login button clicked successsfully");
log.debug("Test#1----------------------Login on the Home Page -----------------Passed");
}
catch(Exception e) {
Assert.assertFalse(false,"Error while clicking on the Login button on the first page");
log.error(e);
log.debug("Test#1----------------------Login on the Home Page ----------------Failed");
}
}
The property value is fetched properly. I have tried printing its value on the console.
It shows up like > By.xpath : "xpathexpression"
The code runs without any errors when I pass the xpath value without using the properties file.
Please help.
I randomly face the issue of missing first character in the ExtJS5 input field, while sending string via sendKeys method.
System info:
Ubuntu 14.04 -> docker containers with selenium grid (2.48.2)
Browser Firefox
Code is simple. I just get input web element, wait if it's clickable (i.e. isEnabled and isDisplayed), clear and send string:
wait.until(ExpectedConditions.elementToBeClickable(input)).clear();
input.sendKeys(value);
input element is simple too:
<input id="textfield-1455-inputEl" data-ref="inputEl" type="text" role="textbox" size="1" name="name" class="x-form-field x-form-required-field x-form-text x-form-text-default x-form-focus x-field-form-focus x-field-default-form-focus" autocomplete="off" componentid="textfield-1455"/>
I've noticed that issue occurs only for the first sendKeys() executing on the page:
Enter the page, wait for page load, work with first input
Enter the page, wait for page load, choose Enable into corresponding select box in order to enable input field, work with input field (image with this example is attached)
Enter the page, wait for page load, click button add in order to add the needed input field, work with input field
Other occurrences of the sendKeys on the page are stable.
I've looked for similar questions. It does not seem the issue with special characters (Missing characters example: 46-> 6; coverTest -> overTest; 1 -> nothing);
Also, I don't think it's an issue with missing characters due to remote webdriver infrastructure. The tests fail randomly but in exact places.
I know that I can use sendKeys(), then check the value of the input and repeat the sending action. However, it's the last option.
Is there any additional check needed for ExtJS input (any attribute in DOM) in order to be sure that input field is ready?
Appreciate your help.
Some times it happens with me. Try clicking on to the field first, but it's a wild guess assuming there can be some focus related issues.
Your sequence could be somewhat like this:
wait.until(ExpectedConditions.elementToBeClickable(input)).click();
input.clear();
input.sendKeys(value);
Weird thing is that I actually faced a situation, where I clicked it twice before sending values and it worked somehow :P
Another thing to try could be using a non-native javascript executor.
JavascriptExecutor myExecutor = ((JavascriptExecutor) driver);
myExecutor.executeScript("arguments[0].value='6';", input);
Sorry man, if the system would have been in front of me I'd have tried much more things.
I was struggling with sendKeys failing my self, but the following works pretty consistently. The method findVisibleElement is a custom wrapper for driver.until....
protected static boolean sendKeysByChar(By by, String input)
{
WebElement field = driver.findVisibleElement(by).base();
field.click();
field.clear();
for (int i = 0; i < input.length(); i++) {
String current = driver.findElement(by).getAttribute("value");
String nextChar = String.valueOf(input.charAt(i));
while (current.length() <= i || !current.endsWith(nextChar)) {
field.sendKeys(nextChar);
current = driver.findElement(by).getAttribute("value");
}
}
field = driver.findElement(by); // Refresh element
if (field.getAttribute("value").equals(input)) { return true; }
log.warn("Send keys by char failed.");
return false;
}
I'm using nightwatch with selenium for automation testing. I'm trying to use the selenium command 'elements' which takes a css selector or xpath as the first parameter, but keep getting the following error :
Error while running elements command: Please provide any of the following using strings as the first parameter: class name, css selector, id, name, link text, partial link text, tag name or xpath
My use is like this:
module.exports = {
"My test" : function (browser) {
...
// want to get all the input elements from the document
browser.elements('input','name', function(els){
// of xpath like this
browser.elements('//input','name', function(els){
});
}
}
Any ideas why I'm getting this error? Thanks!
Ah I figured it out - the first param is a keyword which has to be one of these (from nightwatch selenium protocols.js)
var check = /class name|css selector|id|name|link text|partial link text|tag name|xpath/gi;
So the command needs to look like this :
browser.elements('tag name', 'input', function(el){
})