Hello. This is @mochio from QA. This article is the 20th day of LIFULL Advent Calendar 2017.
We carry out automated tests in our business, and we use Selenium there. Please refer to various articles about Selenium. I made it to organize it because it gets confused because the writing style is a little different between languages.
Java
driver.get("URL");
C#
driver.Url = "URL";
Python
driver.get("URL")
Ruby
driver.get("URL")
Java
driver.navigate().to("URL");
C#
driver.Navigate().GoToUrl("URL");
Python
driver.get("URL")
Ruby
driver.navigate.to("URL")
Java
driver.navigate().back();
C#
driver.Navigate().Back();
Python
driver.back()
Ruby
driver.navigate.back
Java
driver.navigate().forward();
C#
driver.Navigate().Forward();
Python
driver.forward()
Ruby
driver.navigate.forward
Java
driver.navigate().refresh();
C#
driver.Navigate().Refresh();
Python
driver.refresh()
Ruby
driver.navigate.refresh
Java
driver.getCurrentUrl()
C#
driver.Url;
Python
driver.current_url
Ruby
driver.current_url
Java
driver.getTitle():
C#
driver.Title;
Python
driver.title
Ruby
driver.title
Java
driver.getPageSource();
C#
driver.PageSource;
Python
driver.page_source
Ruby
driver.page_source
Java
driver.close();
C#
driver.Close();
Python
driver.close()
Ruby
driver.close
Java
driver.quit();
C#
driver.Quit();
Python
driver.quit()
Ruby
driver.quit
Java
driver.findElement(By.className("classname")); //Specify by class
driver.findElement(By.id("id")); //Specify by id
driver.findElement(By.xpath("xpath")); //Specify by xpath
C#
driver.FindElement(By.ClassName("classname")); //Specify by class
driver.FindElement(By.Id("id")); //Specify by id
driver.FindElement(By.Xpath("xpath")); //Specify by xpath
Python
driver.find_element_by_class_name("classname") #Specify by class
driver.find_element_by_id("id") #Specify by id
driver.find_element_by_xpath("xpath") #Specify by xpath
Ruby
driver.find_element(:class, "classname") #Specify by class
driver.find_element(:id, "id") #Specify by id
driver.find_element(:xpath, "xpath") #Specify by xpath
Java
driver.findElement(By.XPath("XPATH")).click();
C#
driver.FindElement(By.XPath("XPATH")).Click();
Python
driver.find_element_by_xpath("XPATH").click()
Ruby
driver.find_element(:xpath, "XPATH").click
Java
WebElement element = driver.findElement(By.id("ID"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
C#
var element = driver.FindElement(By.id("ID"));
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.Perform();
Python
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_id("ID")
actions = ActionChains(driver)
actions.move_to_element(element)
actions.perform()
Ruby
driver.find_element(:id, "ID").location_once_scrolled_into_view
Java
element = driver.findElement(By.xpath("xpath"));
Select(element).selectByIndex(indexnum); //Select by index
Select(element).selectByValue("value"); //value of value
Select(element).selectByVisibleText("text"); //Display text
C#
element = driver.FindElement(By.Xpath("xpath"));
Select(element).SelectByIndex(indexnum); //Select by index
Select(element).SelectByValue("value"); //value of value
Select(element).SelectByText("text"); //Display text
Python
element = driver.find_element_by_xpath("xpath")
Select(element).select_by_index(indexnum) #Select by index
Select(element).select_by_value("value") #value of value
Select(element).select_by_visible_text("text") #Display text
Ruby
element = driver.find_element(:xpath, "xpath")
Select(element).select_by(:index, indexnum) #Select by index
Select(element).select_by(:value, "value") #value of value
Select(element).select_by(:text, "string") #Display text
Java
driver.findElement(By.id("ID")).sendKeys("string");
C#
driver.FindElement(By.id("ID")).SendKeys("string");
Python
driver.find_element_by_id("ID").send_keys("strings")
Ruby
driver.find_element(:id, "ID").send_keys("strings")
Java
driver.findElement(By.id("ID")).getText();
C#
driver.FindElement(By.id("ID")).Text;
Python
driver.find_element_by_id("ID").text
Ruby
driver.find_element(:id, "ID").text
Java
driver.findElement(By.id("ID")).getAttribute("value");
C#
driver.FindElement(By.id("ID")).GetAttribute("value");
Python
driver.find_element_by_id("ID").get_attribute("value")
Ruby
driver.find_element(:id, "ID").attribute("value")
Java
driver.switchTo().alert().accept();
C#
driver.SwitchTo().Alert().Accept();
Python
Alert(driver).accept()
Ruby
driver.switch_to.alert.accept
Java
driver.manage().window().maximize();
C#
driver.Manage().Window().Maximize();
Python
driver.maximize_window()
Ruby
driver.manage.window.maximize
Java
driver.findElement(By.xpath("xpath")).isDisplayed();
C#
driver.FindElement(By.Xpath("xpath")).Displayed();
Python
driver.find_element_by_xpath("xpath").is_displayed()
Ruby
driver.find_element(:xpath, "xpath").displayed?
Java
driver.findElement(By.xpath("xpath")).isEnabled();
C#
driver.FindElement(By.Xpath("xpath")).Enabled();
Python
driver.find_element_by_xpath("xpath").is_enabled()
Ruby
driver.find_element(:xpath, "xpath").enabled?
Java
driver.findElement(By.xpath("xpath")).isSelected();
C#
driver.FindElement(By.Xpath("xpath")).Selected();
Python
driver.find_element_by_xpath("xpath").is_selected()
Ruby
driver.find_element(:xpath, "xpath").selected?
I made it and saw it, but it was all similar. I would appreciate it if you could point out any mistakes. We will add it as needed if requested. Please let me know if there are other useful methods you can use: bow:
Recommended Posts