In the following code, preBlur event is not getting fired in Selenium Webdriver.
var monikerOldValue = '';
this.editor.on( 'open', function ( e, type ) {
monikerOldValue = self.editor.get().moniker;
}).on( 'preBlur', function ( e ) {
self.isDirty = self.editor.get().moniker !== monikerOldValue;
});
I am using jQuery editor for inline editing.
Using selenium chrome WebDriver to run automation test case.
Any fix for that?
I solved it temporarily by using blur event.
Related
I want to do testing using selenium webdriver in Jmeter. And i was using By.linkText to find an element, and assert whether the element exists or not.
var elements = WDS.browser.findElements(pkg.By.linkText("Tools"));
eval(elements.length != 0);
But it seems if replace 'Tools' with any other string like 'asfasdsa' it will return True, and my test is passing. It seems By.linkText doesnt work in JMeter. Is there any other alternate way to find an element in webpage other than By.id??
Also, is this a good way to verify whether an element is present?
Selenium works just fine, I'm not sure what you're trying to do with eval(elements.length != 0); function call, it will return false but fail to see where and how you're using this value
If you want to fail the WebDriver Sampler when the number of returned elements is 0 you need to do this a little bit differently, in particular conditionally call WDS.sampleResult.setSuccessful() function
Suggested code change:
WDS.sampleResult.sampleStart()
WDS.browser.get('http://example.com')
var elements = WDS.browser.findElements(org.openqa.selenium.By.linkText('More information...'))
if (elements.length == 0) {
WDS.sampleResult.setSuccessful(false)
WDS.sampleResult.setResponseMessage('Failed to find any element matching the criteria')
}
WDS.sampleResult.sampleEnd()
The above code will pass as long as you don't change More information... to something else.
See The WebDriver Sampler: Your Top 10 Questions Answered for more WebDriver Sampler tops and tricks
You can use xpath:
Using text():
var elements = WDS.browser.findElements(pkg.By.xpath("//*[text()='Tools']"));
eval(elements.length != 0);
Using contains():
var elements = WDS.browser.findElements(pkg.By.xpath("//*[contains(., 'Tools')]"));
eval(elements.length != 0);
I'm writing Android Web automated test using Kotlin+Selenide+Appium. There's already working Desktop Web version of those tests on Kotlin+Selenide.
Koltin 1.2.31
Selenide:4.11.1
Appium:java-client:5.0.4
Appium: 1.7.2
Test starts, appium server starts, browser on my device starts, page opens, element is located but it cannot setValue for it. Test works well except for Input elements and manipulations on it.
In test, I clear the field at first, then I set value for it. It actually find the element, clears it and then throws the error on that step (clear the field). So it clears the field but it also cannot found it???
Errors that appear:
Element not found {.project-scope-main-header-content-input > div > input}
Expected: exist
Caused by: WebDriverException: unknown error: call function result missing 'value'
I tried to run the tests with and without these 2 capabilities:
capa.setCapability("unicodeKeyboard", true)
capa.setCapability("resetKeyboard", true)
Appreciate any help. Thanks.
EDIT: The problem is in outdated ChromeDriver which I cannot update for some reasons.
EDIT#2:
Here's how I initialize it:
`
lateinit var driver: AppiumDriver<SelenideElement>
private val appiumServer = AppiumRunAndStop()
#BeforeClass
#Parameters("platform")
fun setUp(platform : String) {
appiumServer.restartServer()
when (platform) {
"Android" -> {
val capa = DesiredCapabilities()
capa.setCapability("automationName", "Appium")
//capa.setCapability("newCommandTimeout", 150)
capa.setCapability("platformName", "Android")
capa.setCapability("platformVersion", "8.1.0")
capa.setCapability("deviceName", "Nexus 6P")
capa.setCapability("browserName", "Chrome")
capa.setCapability("unicodeKeyboard", true)
capa.setCapability("resetKeyboard", true)
capa.setCapability("chromedriverExecutable", "pathh\\chromedriver_win32\\chromedriver.exe")
driver = AppiumDriver(URL("http://127.0.0.1:4723/wd/hub"), capa)
sleep(2000)
WebDriverRunner.setWebDriver(driver)
}
"iOS" -> {
//TO DO
}
else -> println("Platform is not correct")
}
Configuration.baseUrl = "my_url"
}`
It works with this capa.setCapability("chromedriverExecutable", "pathh\\chromedriver_win32\\chromedriver.exe") but I want it to autoupdate the ChromeDriver automatially.
Did you tried using element.sendKeys("your value") method to enter values and element.clear() to clear the text from the element?
This approach works for me. Also avoid using beta version of Appium Java client and always use a stable version which is 5.0.4.
I found the problem. My test uses outdated ChromeDriver (chromedriver=2.33.506120).
I don't know how to update it for this test.
WebDriverManager.chromedriver().version("2.37").setup() doesn't help.
System.setProperty("webdriver.chrome.driver","path\\chromedriver_win32\\chromedriver.exe") either doesn't help.
I also tried to do this:
val options = ChromeOptions()
options.addArguments("androidPackage", "com.android.chrome")
capa.setCapability(ChromeOptions.CAPABILITY, options)`
EDIT: Worked with capa.setCapability("chromedriverExecutable", "PATH") but why Selenide doesn't update ChromeDriver by itself?
As we know iframe can be counted using frameslist but that doesn't work for me and gives blank output although frame count gives me count as 2. I'm using Selenium WebDriver and Java.
Basically I want to get img source's data-mce-src starts with cid and dfsrc ends with # according to below screenshot.
I tried :
public static final String imageAttachment="css=img[data-mce-src^='cid']&&[data-mce-src$='#']";
which works fine using sIsElementPresent in selenium 1.0 but it fails in webdriver using findElement. In fact it doesn't identify iframe itself.
Expected:
css=img[data-mce-src^='cid']&&[data-mce-src$='#'] element present?
Code:
WebElement we = null;
List <WebElement> framesList = webDriver().findElements(By.tagName("iframe"));
for (WebElement frame:framesList){
System.out.println(frame.getText()); // returns nothing
}
int listSize = framesList.size();
webDriver().findElement(By.xpath("//iframe"));
System.out.println(listSize);
Also tried:
webDriver().switchTo().frame(webDriver().findElements(By.tagName("iframe"));
we = webDriver().findElement(By.cssSelector("html body div img"));
System.out.println(we.getAttribute("src")); // returns nothing
You should try as below :-
webDriver().switchTo().frame("Editor1_body_ifr");
we = webDriver().findElement(By.cssSelector("body#tinymce img"));
System.out.println(we.getAttribute("src"));
try {
webDriver().switchTo().frame("Editor1_body_ifr");
we = webDriver().findElement(By.cssSelector("html body img"));
System.out.println(we.getAttribute("src"));
System.out.println(we.getAttribute("data-mce-src"));
System.out.println(we.getAttribute("dfsrc"));
} finally {
webDriver.switchTo().defaultContent();
}
I'm trying to automate the webpage "http://www.quikr.com",when I open this you will get a pop up window first saying "Please Choose Your Location" then after closing it , I can see the main page of quikr.
I tried closing that Popup page by automation ,but not able to do
Tried using xpath
driver.findElement(By.xpath("//*[#id='csclose']/strong")).click();
Tried using className
driver.findElement(By.className("cs-close cs-close-v2")).click();
Tried using id
driver.findElement(By.id("csclose")).click();
Please help me with this
to close multiple popups in webdriver and switch to parent window
String parent = driver.getWindowHandle();
Set<String> pops=driver.getWindowHandles();
{
Iterator<String> it =pops.iterator();
while (it.hasNext()) {
String popupHandle=it.next().toString();
if(!popupHandle.contains(parent))
{
driver.switchTo().window(popupHandle);
System.out.println("Popu Up Title: "+ driver.switchTo().window(popupHandle).getTitle());
driver.close();
The Following Code Works for Me to Handle Pop Up/ Alerts in Selenium Webdriver
Just Copy Paste this Code After the Event which is triggering the Pop up/Alert i.e after clicking on save.
if(driver.switchTo().alert() != null)
{
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
alert.dismiss(); // alert.accept();
}
in your case you try to run this code at starting of the code bcz it will directly close the pop up
Since this is a JavaScript modal, when the page finishes loading the JavaScript code could still be running. The solution is to wait until the button to close the modal be displayed, close it and then follow with your test. Like this:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("csclose")));
driver.FindElement(By.Id("csclose")).Click();
Tested myself and works fine.
Hope it helps.
i have tried it in ruby and this one works
see if this can help you in any way :)
require 'selenium-webdriver'
require 'test/unit'
require 'rubygems'
class Tclogin < Test::Unit::TestCase #------------ define a class----------------
def setup
##driver = Selenium::WebDriver.for :firefox
##driver.navigate.to "http://www.quikr.com" #---- call url----
##wait = Selenium::WebDriver::Wait.new(:timeout => 60) # seconds #----define wait------
end
def test_login
##driver.find_element(:css, "strong").click
end
end
you can also use follwing xpath
##driver.find_element(:xpath, "//a[#id='csclose']/strong").click
public void closePopup() throws Exception {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.quikr.com/");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("csclose"))).click();
System.out.println("Successfully closed the start Popup");
}
Try driver.findElement(By.Id("csclose")).click(); I hope that will help
Simple pressing Alt + F4 buttons worked for me, e.g.:
driver.findElement(By.cssSelector("html body div div img")).sendKeys(Keys.chord(Keys.ALT, Keys.F4));
Using Selenium's Firefox WebDriver 2.20, I need to display a tooltip that appears when the mouse hovers over a link on my web page.
I've tried using Selenium's Action class to do this, but I get a ClassCastException: $Proxy7 incompatible with org.openqa.selenium.internal.Locatable. Here is what I've tried so far:
Actions builder = new Actions(driver);
WebElement link = driver.findElement(By.tagName("a"));
builder.moveToElement(link).build().perform();
The ClassCastException happens in the moveToElement() method, when the WebElement that I passed to the function is cast to a Locatable object. The method is:
public Actions moveToElement(WebElement toElement) {
action.addAction(new MoveMouseAction(mouse, (Locatable) toElement));
return this;
}
I've also tried the code below, which resulted in the same error:
WebElement link = driver.findElement(By.tagName("a"));
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseDown(((Locatable)link).getCoordinates());
I've heard that these methods worked in previous Firefox versions but not with recent Firefox versions (I'm using FF12). If that is true, are there any other ways of simulating a mouseover in Selenium? Any help getting this function to work would be greatly appreciated!
SOLUTION
After digging around for a while and trying different code snippets, I found a solution to the problem. For anyone who has this problem in the future, I had to disable native events for the Firefox driver, like so:
DesiredCapabilities cap = DesiredCapabilities.firefox();
FirefoxProfile prof = new FirefoxProfile();
prof.setEnableNativeEvents(false);
cap.setCapability("firefox_profile", prof);
You can use Javascript to do that:
string script = "var evt = document.createEvent('MouseEvents');" +
"evt.initMouseEvent('mouseover',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +
"arguments[0].dispatchEvent(evt);";
((IJavaScriptExecutor)driver).ExecuteScript(script, element);