How do I get current URL in Selenium Webdriver 2 Python?
Use current_url element for Python 2: print browser.current_url For Python 3 and later versions of selenium: print(driver.current_url)
Use current_url element for Python 2: print browser.current_url For Python 3 and later versions of selenium: print(driver.current_url)
You can also check pageloaded using following code IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00)); wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript(“return document.readyState”).Equals(“complete”));
Thumb rule A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing –no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome … Read more
Selenium provides a convenient Select class to work with select -> option constructs: from selenium import webdriver from selenium.webdriver.support.ui import Select driver = webdriver.Firefox() driver.get(‘url’) select = Select(driver.find_element_by_id(‘fruits01’)) # select by visible text select.select_by_visible_text(‘Banana’) # select by value select.select_by_value(‘1′) See also: What is the correct way to select an using Selenium’s Python WebDriver?
This is a good question I have seen people use Close() when they shouldn’t. I looked in the source code for the Selenium Client & WebDriver C# Bindings and found the following. webDriver.Close() – Close the browser window that the driver has focus of webDriver.Quit() – Calls Dispose() webDriver.Dispose() Closes all browser windows and safely … Read more
Try the following: driver.find_elements_by_xpath(“//*[contains(text(), ‘My Button’)]”)
You can use document.evaluate: Evaluates an XPath expression string and returns a result of the specified type if possible. It is w3-standardized and whole documented: https://developer.mozilla.org/en-US/docs/Web/API/Document.evaluate function getElementByXpath(path) { return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } console.log( getElementByXpath(“//html[1]/body[1]/div[1]”) ); <div>foo</div> https://gist.github.com/yckart/6351935 There’s also a great introduction on mozilla developer network: https://developer.mozilla.org/en-US/docs/Introduction_to_using_XPath_in_JavaScript#document.evaluate Alternative version, using XPathEvaluator: … Read more
This is caused by following 3 types: 1.The element is not visible to click. Use Actions or JavascriptExecutor for making it to click. By Actions: WebElement element = driver.findElement(By(“element_path”)); Actions actions = new Actions(driver); actions.moveToElement(element).click().perform(); By JavascriptExecutor: JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript(“scroll(250, 0)”); // if the element is on top. jse.executeScript(“scroll(0, 250)”); // if the … Read more
Java Yes, it is possible. The following example is in Java: WebDriver driver = new FirefoxDriver(); driver.get(“http://www.google.com/”); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy somewhere FileUtils.copyFile(scrFile, new File(“c:\\tmp\\screenshot.png”));
You can read the innerHTML attribute to get the source of the content of the element or outerHTML for the source with the current element. Python: element.get_attribute(‘innerHTML’) Java: elem.getAttribute(“innerHTML”); C#: element.GetAttribute(“innerHTML”); Ruby: element.attribute(“innerHTML”) JavaScript: element.getAttribute(‘innerHTML’); PHP: $element->getAttribute(‘innerHTML’); It was tested and worked with the ChromeDriver.