Posts

Showing posts with the label Selenium Webdriver

Best Way To Check That Element Is Not Present Using Selenium WebDriver With Java

Answer : Instead of doing findElement, do findElements and check the length of the returned elements is 0. This is how I'm doing using WebdriverJS and I expect the same will work in Java i usually couple of methods (in pair) for verification whether element is present or not: public boolean isElementPresent(By locatorKey) { try { driver.findElement(locatorKey); return true; } catch (org.openqa.selenium.NoSuchElementException e) { return false; } } public boolean isElementVisible(String cssLocator){ return driver.findElement(By.cssSelector(cssLocator)).isDisplayed(); } Note that sometimes selenium can find elements in DOM but they can be invisible, consequently selenium will not be able to interact with them. So in this case method checking for visibility helps. If you want to wait for the element until it appears the best solution i found is to use fluent wait: public WebElement fluentWait(final By locator){ Wait<WebDriver...

ChromeDriver - Disable Developer Mode Extensions Pop Up On Selenium WebDriver Automation

Answer : Did you try disabling the developer extensions with command line param? Try with the following Selenium WebDriver java code: System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-extensions"); driver = new ChromeDriver(options); I cannot disable extensions because I'm developing & testing one. What I'm doing to dismiss this popup is the following: I load chrome with my extension using Selenium. I then immediately create a new window (via the SendKeys(Control-N) method). This predictably brings up the "Disable Developer Mode Extensions" popup after 3 seconds in the new window. I can't tell programmatically when it pops up (doesn't show in screenshots) so instead I simply wait 4 seconds. Then I close the tab via driver.Close(); (which also closes this new window). Chrome takes that as "cancel", dis...

Click Button By Text Using Python And Selenium

Answer : You can find all buttons by text and then execute click() method for each button in a for loop. Using this SO answer it would be something like this: buttons = driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]") for btn in buttons: btn.click() I also recommend you take a look at Splinter which is a nice wrapper for Selenium. Splinter is an abstraction layer on top of existing browser automation tools such as Selenium, PhantomJS and zope.testbrowser. It has a high-level API that makes it easy to write automated tests of web applications. I had the following in html: driver.find_element_by_xpath('//button[contains(text(), "HELLO")]').click()