For this line of code in Selenium:
driver = WebDriverManager.startDriver(browser, useragent)
where
browser = context.getCurrentXmlTest().getParameter("browser"); and
useragent = context.getCurrentXmlTest().getParameter(useragent);
Does anybody know what this line is doing? And where do we use WebDriver Manager?
I assume the "where", "and" stuff is just setting the parameters for that function, cucumber type coding. So you would be pulling those parameters from some kind of context configuration.
It looks like WebDriverManager helps you set up the type of driver you want. Making it easy to change from firefox, chrome, IE by hiding the configuration into that class.
ITestContext is interface in TestNG which helps here, to get current Test which is under execution and fetching variables provided for that test. If i want to say in Java prospective, lets say you provided variable 'browser' with value as 'chrome' in testng.xml file for this test. This peace of code
browser = context.getCurrentXmlTest().getParameter("browser");
get that variable value 'chrome' and assigning this to 'browser' variable in this class.
Regarding WebDriverManager, i am not yet used but for code provide it looks like peace of code or library which helps you start driver. To start the driver you are passing which driver need to start like chrome, firefox etc.. For example as here browser value is chrome, so its instantiate ChromeDriver nothing but opens chrome browser and continues execution. I hope you need to use this code to start the driver in normally as replacement of driver=new soandsodriver();
Thank You,
Murali
Related
Here is a reference to the original discussion: Link
There were basically two propositions on how to change the browser when executing a test using Selenide.
One was:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
System.setProperty("selenide.browser", "Chrome");
open("http://google.com");
and the other was:
Configuration.browser = "chrome";
open("http://google.com");
Both seem to do the same thing. What is the difference?
The comment in the original post from Paul Nelson Baker explains this:
While this is true for a starting a general ChromeDriver, this is
specifically asking for Selenide which wraps Selenium.
This means following piece of code is used to start a driver using Selenium:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
System.setProperty("selenide.browser", "Chrome");
open("http://google.com");
While following code can only be used with Selenide:
Configuration.browser = "chrome";
open("http://google.com");
Note that with Selenide both methods are working because Selenide is built around Selenium.
If you need more information about it take a look at Selenide on GitHub.
Basically, Selenide.open performs a call on SelenideDriver.open where a new instance of StaticConfig is created. In the class StaticConfig is the call to the static field browser located.
Hi I've been trying to figure this for the past couple of days. I wrote the code below that use to work but doesn't work any more using the ExecuteScript method. The only thing i have changed was update my chrome driver because it was not launching chrome since the driver wasn't working with the older chrome version I have. So once I updated the chrome driver it began to work until i had to run this piece of code. I modified it below not to what the actual link text is.
IJavaScriptExecutor js = (IJavaScriptExecutor)WebActions.One;
js.ExecuteScript("alert('Welcome to Guru99');"); // This was added for testing purpose
IWebElement somelink = WebActions.One.FindElement(By.XPath("//span[text()='Some Text']"));
js.ExecuteScript("arguments[0].click();", somelink );
When i changed the method to be ExecuteAsyncScript it started working again. Is this something that has changed with the app or is this something i'm doing wrong. I tried reading up on ExecuteAsyncScript vs ExecuteScript to see the difference but all i was able to get was something about the call back telling
when its finished which i'm not experienced in java script.
I would just like to understand more then anything or should i just start using ExecuteAsyncScript method. Thanks
There's a chromedriver ticket about this issue here:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=3103
It states:
The cause of the issue is this website modifies the constructor of the
built-in AsyncFunction object. This causes difficulty when
ChromeDriver tries to create an AsyncFunction to wrap the script being
executed.
chromedriver 78 fixes the issue. For testing with Chrome 77, the ticket recommends switching to executeAsyncScript, or using chromedriver 76 since "ChromeDriver vX will run with Chrome vX+1".
In Chrome, shift-escape gives you Chrome's task manager.
In the task manager, you can see various stats, including the "memory footprint" of a tab.
I'd like to get that value in Selenium. Is there a way to do so?
Apparently there is a chrome.processes API which looks like it could be useful, if it could be accessed from Selenium.
You can execute arbitrary JavaScript code from Selenium therefore you can access i.e. Window.Performance object in general and Windows.Performance.Memory object in particular
Example code:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://accounts.seetest.io/signup')
print(driver.execute_script("return window.performance.memory"))
driver.quit()
Example output:
{'jsHeapSizeLimit': 2197815296, 'totalJSHeapSize': 23449360, 'usedJSHeapSize': 14905688}
I've tried the standard
var elementForMs = driver.findElement(By.xpath(selector));
driver.executeScript("arguments[0].click()", elementForMs);
and
var elementForMs = driver.findElement(By.css(selector));
driver.executeScript("arguments[0].click()", elementForMs);
And there are simply cases where the element never responds to the click in Microsoft Edge 15.01563.
Each driver has unique bugs. So somethings that work in Firefox, may not work in Chrome or so on. So the only way around is to find what works and use it. And if possible report the issue to the driver owner
In your case since finding the element and clicking on it doesn't work with
var elementForMs = driver.findElement(By.xpath(selector));
driver.executeScript("arguments[0].click()", elementForMs);
But works when you use javascript directly in console. that means you should execute the same in your code
driver.executeScript("document.getElementXXX().click()");
Hi I am trying to run my selenium webdriver on IE9.
WebDriver version : 2.32.0
IE:9
IEDriverServer_win32:2.32.3
windows7
Below is my code:
File IEDriver=new File(System.getProperty("user.dir")+File.separator+"BrowserDrivers"+File.separator+"IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", IEDriver.getAbsolutePath());
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver=new InternetExplorerDriver(cap);
driver.get("http://in00616:8421/GS");
Thread.sleep(3000);
//driver.findElement(By.id("j_username")).sendKeys("admin");
//driver.findElement(By.id("j_password")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_username']")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_password']")).sendKeys("admin");
driver.findElement(By.id("login")).submit();
Thread.sleep(2000);
driver.findElement(By.xpath(".//button[text()='Securities']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//span[text()='Issue']")).click();
Thread.sleep(2000);
driver.findElement(By.id("tabSecurities_Issue_Request_for_Issues")).click();
Above code logs in to my site but then when I try to click on Securities button I am not able to do it. Securities button starts flickering and then I am notified that unable to find the element.
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Unable to find element with xpath == .//span[text()='Issue Type']
(WARNING: The server did not provide any stacktrace information) –
Same code works fine in FireFox.
Please help as i am suppose to test my UI on InternetExplorer.
I think it is the version compatibility issue.
Can anyone suggest the compatible version set for IEDriverServer, Selenium WebDriver and IE which is in working condition.
As this SO answer points out, IE does not have native XPath support. Instead, Selenium WebDriver uses an old third party xpath library when IE is being used. Firefox has integrated support for XPath, which is why your selectors work fine in that browser.
I would highly recommend you update your selectors to instead use CSS selectors. They are supported across all browser, are easier to read, understand, and pick up, and they are pretty fast.
You can learn more about how to use CSS selectors from some different tuturials here, here, and here, and a CSS selectors cheatsheet.
Also, whenever possible, please try to not select an element by the text it contains. If you can select an element by its ID, class, other attribute, or even through the DOM chain (i.e. "div.1 > div.2 > span.a > a.b"), is better than trying to select an element by text.
Webdriver has difficulty with IE using locators. It seems like Murnal has difficulty using CSS locator. My advice would be you HAVE to use other locators if one doesnt work. This issue comes again and again while using non firefox browser. In the meantime an easier way to come up with alternate locator is use Firefox selenium IDE, there in the boxes where you type command you will see it gives alternate locator as well. Copy that and try plugging tha in your webdriver's findelement script.
Hi all i have found out that it was the issue of Selenium Webdriver 2.32 with IEDriver_Server2_32. After trying out permutation & Combination with latest available webdriver versions and IEDriver_Server, i have found out suitable stable configuration to work on IE9 below is the stable configuration : Webdriver : 2.33.0 IEDriver_Server : 2.33.0. There is still small issue but i am trying to look for workaround. Issue : In IE if some control's tooltip overlaps other control than IE is not able to find out that control. i guess this issue is with IEs working. IE uses nativeEvents to perform operation hence it is not able to locate that control. In FF it is able to find out that control and it is working fine. Thanks everyone.