from selenium import webdriver from selenium webdriver common by impor

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
import unittest
class Test2(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_2(self):
driver=self.driver
driver.get("http://www.itbox.ua/")
driver.find_element_by_id("o27427").click()
driver.find_element_by_xpath("//div[7]/div[2]/id('filteres_line')/div/div/div[2]/a").click()
driver.find_element_by_id("buy149821").click()
driver.find_element_by_xpath("//div[4]/div[2]/div/div[2]/div/span[1]/span").click()
driver.find_element_by_xpath("id('cart_contents')/x:form/x:p/x:input[4]").click()
for i in range(60):
try:
if self.is_element_present(By.XPATH, "//tbody[@id='cart_table']/tr/td[2]"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.close()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()