How to upload file ( picture ) with selenium, python
What I’m doing is this (make sure drv is an instance of webdriver): drv.find_element_by_id(“IdOfInputTypeFile”).send_keys(os.getcwd()+”/image.png”) and then find your submit button and click it.
What I’m doing is this (make sure drv is an instance of webdriver): drv.find_element_by_id(“IdOfInputTypeFile”).send_keys(os.getcwd()+”/image.png”) and then find your submit button and click it.
You can find a parent element by using .. xpath: input_el = driver.find_element_by_name(‘A’) td_p_input = input_el.find_element_by_xpath(‘..’) What about making a separate xpath for getting selected option, like this: selected_option = driver.find_element_by_xpath(‘//option[@selected=”selected”]’)
If you have pip installed you can install selenium like so. pip install selenium or depending on your permissions: sudo pip install selenium For python3: sudo pip3 install selenium As you can see from this question pip vs easy_install pip is a more reliable package installer as it was built to improve easy_install. I would … Read more
Scenario/Test steps: 1. Open a browser and navigate to TestURL 2. Scroll down some pixel and scroll up For Scroll down: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript(“window.scrollBy(0,250)”); OR, you can do as follows: jse.executeScript(“scroll(0, 250);”); For Scroll up: jse.executeScript(“window.scrollBy(0,-250)”); OR, jse.executeScript(“scroll(0, -250);”); Scroll to the bottom of the page: Scenario/Test steps: … Read more
Ok, finally figured it out: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # enable browser logging d = DesiredCapabilities.CHROME d[‘loggingPrefs’] = { ‘browser’:’ALL’ } driver = webdriver.Chrome(desired_capabilities=d) # load the desired webpage driver.get(‘http://foo.com’) # print messages for entry in driver.get_log(‘browser’): print(entry) Entries whose source field equals ‘console-api’ correspond to console messages, and the message … Read more
You can try to get the list of all elements with class = “content” by using find_elements_by_class_name: a = driver.find_elements_by_class_name(“content”) Then you can click on the link that you are looking for.
Capybara >= 2.3 includes the new window management API. It can be used like: new_window = window_opened_by { click_link ‘Something’ } within_window new_window do # code end
I have a solution for this issue, check the code: FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference(“browser.download.folderList”,2); firefoxProfile.setPreference(“browser.download.manager.showWhenStarting”,false); firefoxProfile.setPreference(“browser.download.dir”,”c:\\downloads”); firefoxProfile.setPreference(“browser.helperApps.neverAsk.saveToDisk”,”text/csv”); WebDriver driver = new FirefoxDriver(firefoxProfile);//new RemoteWebDriver(new URL(“http://localhost:4444/wd/hub”), capability); driver.navigate().to(“http://www.myfile.com/hey.csv”);
If you are using Webdriver then the item you are looking for is Selected. Often times in the render of the checkbox doesn’t actually apply the attribute checked unless specified. So what you would look for in Selenium Webdriver is this isChecked = e.findElement(By.tagName(“input”)).Selected; As there is no Selected in WebDriver Java API, the above … Read more
Even though I’m somewhat late answering the question: You can now use WebElement.isDisplayed() to check if an element is visible. Note: There are many reasons why an element could be invisible. Selenium tries cover most of them, but there are edge cases where it does not work as expected. For example, isDisplayed() does return false … Read more