How do I use Selenium in C#?

From the Selenium Documentation: using OpenQA.Selenium.Firefox; using OpenQA.Selenium; class GoogleSuggest { static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); //Notice navigation is slightly different than the Java version //This is because ‘get’ is a keyword in C# driver.Navigate().GoToUrl(“http://www.google.com/”); IWebElement query = driver.FindElement(By.Name(“q”)); query.SendKeys(“Cheese”); System.Console.WriteLine(“Page title is: ” + driver.Title); driver.Quit(); } }

Set Chrome’s language using Selenium ChromeDriver

You can do it by adding Chrome’s command line switches “–lang”. Basically, all you need is starting ChromeDriver with an ChromeOption argument –lang=es, see API for details. The following is a working example of C# code for how to start Chrome in Spanish using Selenium. ChromeOptions options = new ChromeOptions(); options.addArguments(“–lang=es”); ChromeDriver driver = new … Read more

Webdriver Screenshot

Use driver.save_screenshot(‘/path/to/file’) or driver.get_screenshot_as_file(‘/path/to/file’): import selenium.webdriver as webdriver import contextlib @contextlib.contextmanager def quitting(thing): yield thing thing.quit() with quitting(webdriver.Firefox()) as driver: driver.implicitly_wait(10) driver.get(‘http://www.google.com’) driver.get_screenshot_as_file(‘/tmp/google.png’) # driver.save_screenshot(‘/tmp/google.png’)

How to mouse hover using java through selenium-webdriver and Java

To Mouse Hover over Electornics menu and select Camera & Photo you can use the following code block : driver.get(“http://demo.nopcommerce.com/”); Actions act = new Actions(driver); WebDriverWait wait = new WebDriverWait(driver, 10); WebElement electronics = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//li/a[@href=”https://stackoverflow.com/electronics”]”))); act.moveToElement(electronics).perform(); WebElement camera_n_photo = driver.findElement(By.xpath(“//li/a[@href=”https://stackoverflow.com/electronics”]//following::ul/li/a”)); camera_n_photo.click(); System.out.println(“Camera & photo Clicked.”);

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe while opening chrome browser

At a first glance to your code trial it seems there is a minor bug in the value of the argument executable_path. Instead of hromedriver.exe it should have been: # Windows OS driver = webdriver.Chrome(executable_path=r’C:\path\to\chromedriver.exe’) # Linux OS driver = webdriver.Chrome(executable_path=”/path/to/chromedriver”) This error message… selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe …implies that … Read more

Send keys not working selenium webdriver python

As you mentioned send_keys(“TEST”) are not working, there are a couple of alternatives to send a character sequence to respective fields as mentioned below : Use Keys.NUMPAD3 [simulating send_keys(“3”)]: login.send_keys(Keys.NUMPAD3) Use JavascriptExecutor with getElementById : self.driver.execute_script(“document.getElementById(‘login_email’).value=”12345″”) Use JavascriptExecutor with getElementsById : self.driver.execute_script(“document.getElementsById(‘login_password’)[0].value=”password””) Now comming to your specific issue, as you mentioned I tried to use … Read more

selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages using ChromeDriver through Selenium

This error message… selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=a lotows NT 6.1.7601 SP1 x86_64) …implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session. Solution Add the argument –no-sandbox through ChromeOptions() to your existing code as follows: from selenium import webdriver from selenium.webdriver.chrome.options … Read more

How to get attribute value inside a div in webdriver

ieDriver.findElement(By.xpath(“//div[@class=”assign_grid assign_grid_selected”]”)).getAttribute(“login”); I’d also check to ensure that the locators you are using are only bringing back that one element, and not more – to check this, run the same thing using .findElements and verify only one single result is returned. It is common that there are hidden elements in the HTML, and your locator … Read more

OpenQA.Selenium.WebDriverException: ‘Cannot start the driver service on http://localhost:20548/’

OpenQA.Selenium.WebDriverException: ‘Cannot start the driver service on http://localhost:20548/‘ As for this issue, It could be the case that a process of the WebDriver is still running in the background. Please try to fire up Task Manager to see and end it if does. Otherwise, you could try to use the following code to assign the … Read more