selenium-webdriver

Create screenshot only on test failure

让人想犯罪 __ 提交于 2020-02-22 08:38:31
问题 Currently I have a function that creates a screenshot and I call it here def tearDown(self): self.save_screenshot() self.driver.quit() There is also a folder being created which is used to store the screenshots. I don't want this to happen when the test passes. What do I have to add in order for this not to happen? Thanks for all the help 回答1: Here is one way to capture screenshot only when failure: def setUp(self): # Assume test will fail self.test_failed = True def tearDown(self): if self

Get grandParent using xpath in selenium webdriver

空扰寡人 提交于 2020-02-22 05:50:47
问题 <div class="myclass"> <span>...</span> <div> <table> <colgroup>...</> <tbody> <tr>...</tr> <tr> <td> <input ...name="myname" ...> </td> </tr> <tr>...</tr> <tbody> </table> </div> </div> this is my html code ... I have attribute "name" ..so I can access tag ...but from this line I want to access top element. One way is that I write driver.find_element_by_xpath('..') 6-7 times to get that parent but I dont know how many steps I have to go above. I simply want a xpath expression or similar thing

Create custom wait until condition in Python

风格不统一 提交于 2020-02-21 10:27:09
问题 I tried to create a function with custom wait condition in Python. However, I get an error: TypeError: 'bool' object is not callable def waittest(driver, locator, attr, value): element = driver.find_element_by_xpath(locator) if element.get_attribute(attr) == value: return element else: return False wait = WebDriverWait(driver, 10) element = wait.until(waittest(driver, '//div[@id="text"]', "myCSSClass", "false")) 回答1: WebDriverWait(driver, 10).until() accepts a callable object which will

Create custom wait until condition in Python

◇◆丶佛笑我妖孽 提交于 2020-02-21 10:25:30
问题 I tried to create a function with custom wait condition in Python. However, I get an error: TypeError: 'bool' object is not callable def waittest(driver, locator, attr, value): element = driver.find_element_by_xpath(locator) if element.get_attribute(attr) == value: return element else: return False wait = WebDriverWait(driver, 10) element = wait.until(waittest(driver, '//div[@id="text"]', "myCSSClass", "false")) 回答1: WebDriverWait(driver, 10).until() accepts a callable object which will

How to pass string to an XPath containing text?

时光怂恿深爱的人放手 提交于 2020-02-21 07:05:33
问题 I get id of a text which is in selected mode using Selenium Webdriver by using this code: String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='Blue']/..")).GetAttribute("id"); How can i pass string getColour in place of Blue? Thank you 回答1: You can pass a string this way. Try below code string getColourin = "Red"; String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='" + getColourin +"']/..")).GetAttribute("id"); OR using string

How to pass string to an XPath containing text?

泄露秘密 提交于 2020-02-21 07:03:20
问题 I get id of a text which is in selected mode using Selenium Webdriver by using this code: String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='Blue']/..")).GetAttribute("id"); How can i pass string getColour in place of Blue? Thank you 回答1: You can pass a string this way. Try below code string getColourin = "Red"; String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='" + getColourin +"']/..")).GetAttribute("id"); OR using string

How to pass string to an XPath containing text?

拈花ヽ惹草 提交于 2020-02-21 07:03:11
问题 I get id of a text which is in selected mode using Selenium Webdriver by using this code: String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='Blue']/..")).GetAttribute("id"); How can i pass string getColour in place of Blue? Thank you 回答1: You can pass a string this way. Try below code string getColourin = "Red"; String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='" + getColourin +"']/..")).GetAttribute("id"); OR using string

Unable to login to Quora using Selenium webdriver in Python

六月ゝ 毕业季﹏ 提交于 2020-02-20 13:24:27
问题 I am using a Selenium module in Python to log into Quora. It works fine for Facebook, but I am getting an error on the send_keys('my_email') line while trying it on Quora: I am using the following script. from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.Firefox() driver.get('http://www.quora.com/') time.sleep(60) username = driver.find_element_by_name('email') time.sleep(60) username.send_keys('my_email') time.sleep(60) password =

Test canvas drawings with Protractor

柔情痞子 提交于 2020-02-20 08:05:28
问题 Is there a way to test if a drawing was made on a canvas using Protractor ? i.e. I draw a rectangle based on user clicks: var shape = new createjs.Shape(); shape.graphics.beginStroke("black"); shape.graphics.drawRect(crd.x, crd.y, crd.width, crd.height); stage.addChild(shape) stage.update() Now I want to make a spec to test if a rectangle was drawn on the specified coordinates and, as a plus, to test if its borders are of color black. Is this possible using Protractor/WebDriverJS API? 回答1:

How to count no of rows in table from web application using selenium python webdriver

≡放荡痞女 提交于 2020-02-18 04:07:29
问题 How to count the rows in the table from web application by using selenium python web driver. Here we can retrieve all data in the table from web application but couldn't count the rows and columns, please give me idea of how to do this. 回答1: Try some thing like this int rowCount=driver.findElements(By.xpath("//table[@id='DataTable']/tbody/tr")).size(); int columnCount=driver.findElements(By.xpath("//table[@id='DataTable']/tbody/tr/td")).size(); FYI : This is the implementation in java. 回答2: