Python/selenium: Difference between revisions
< Python
(→linux) |
No edit summary |
||
Line 27: | Line 27: | ||
</pre> | </pre> | ||
</blockquote> | </blockquote> | ||
Line 36: | Line 35: | ||
== finding element == | |||
<blockquote> | |||
<pre> | |||
browser.find_element(By.ID, "login-signin").click() | |||
</pre> | |||
</blockquote> | |||
== element operations == | |||
<blockquote> | <blockquote> | ||
<pre> | <pre> | ||
.click() | |||
.send_keys('hello') | |||
.selected? | |||
.click | |||
.clear | |||
.displayed? | |||
.text | |||
.attribute('class') | |||
.get_attribute('innerHTML') | |||
</pre> | </pre> | ||
</blockquote> | </blockquote> |
Revision as of 18:45, 24 November 2017
- imports
import selenium from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import Select from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import TimeoutException
- initialize
def openbrowser(): global browser chrome_options = Options() chrome_options.add_argument("--force-renderer-accessibility") browser = selenium.webdriver.PhantomJS() #browser = selenium.webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=chrome_options) # linux browser.set_window_position(1280, 0) browser.set_window_size(1280, 1400)
- PhantomJS (=headless)
- download PhantomJS and place bin/exec in /usr/local/bin
- or install with npm
finding element
browser.find_element(By.ID, "login-signin").click()
element operations
.click() .send_keys('hello') .selected? .click .clear .displayed? .text .attribute('class') .get_attribute('innerHTML')