File tree Expand file tree Collapse file tree 15 files changed +66
-52
lines changed
course_contents/12_browser_automation_selenium
11_adding_waits_to_our_code
3_using_chrome_in_scraping_code/parsers
4_our_new_page_locators/parsers
5_interacting_with_dropdowns
8_encapsulating_logic_simply
9_adding_some_error_handling Expand file tree Collapse file tree 15 files changed +66
-52
lines changed Original file line number Diff line number Diff line change 1
1
from typing import List
2
+ from selenium .webdriver .common .by import By
2
3
from selenium .webdriver .support .ui import Select
3
4
from selenium .common .exceptions import NoSuchElementException
4
5
@@ -21,22 +22,22 @@ def quotes(self) -> List[QuoteParser]:
21
22
22
23
@property
23
24
def author_dropdown (self ) -> Select :
24
- element = self .browser .find_element_by_css_selector (
25
- QuotesPageLocators .AUTHOR_DROPDOWN
25
+ element = self .browser .find_element (
26
+ By . CSS_SELECTOR , QuotesPageLocators .AUTHOR_DROPDOWN
26
27
)
27
28
return Select (element )
28
29
29
30
@property
30
31
def tags_dropdown (self ):
31
- element = self .browser .find_element_by_css_selector (
32
- QuotesPageLocators .TAG_DROPDOWN
32
+ element = self .browser .find_element (
33
+ By . CSS_SELECTOR , QuotesPageLocators .TAG_DROPDOWN
33
34
)
34
35
return Select (element )
35
36
36
37
@property
37
38
def search_button (self ):
38
- return self .browser .find_element_by_css_selector (
39
- QuotesPageLocators .SEARCH_BUTTON
39
+ return self .browser .find_element (
40
+ By . CSS_SELECTOR , QuotesPageLocators .SEARCH_BUTTON
40
41
)
41
42
42
43
def select_author (self , author_name : str ):
Original file line number Diff line number Diff line change @@ -24,22 +24,22 @@ def quotes(self) -> List[QuoteParser]:
24
24
25
25
@property
26
26
def author_dropdown (self ) -> Select :
27
- element = self .browser .find_element_by_css_selector (
28
- QuotesPageLocators .AUTHOR_DROPDOWN
27
+ element = self .browser .find_element (
28
+ By . CSS_SELECTOR , QuotesPageLocators .AUTHOR_DROPDOWN
29
29
)
30
30
return Select (element )
31
31
32
32
@property
33
33
def tags_dropdown (self ):
34
- element = self .browser .find_element_by_css_selector (
35
- QuotesPageLocators .TAG_DROPDOWN
34
+ element = self .browser .find_element (
35
+ By . CSS_SELECTOR , QuotesPageLocators .TAG_DROPDOWN
36
36
)
37
37
return Select (element )
38
38
39
39
@property
40
40
def search_button (self ):
41
- return self .browser .find_element_by_css_selector (
42
- QuotesPageLocators .SEARCH_BUTTON
41
+ return self .browser .find_element (
42
+ By . CSS_SELECTOR , QuotesPageLocators .SEARCH_BUTTON
43
43
)
44
44
45
45
def select_author (self , author_name : str ):
Original file line number Diff line number Diff line change
1
+ from selenium .webdriver .common .by import By
1
2
from locators .quote_locators import QuoteLocators
2
3
3
4
@@ -11,12 +12,12 @@ def __repr__(self):
11
12
@property
12
13
def content (self ):
13
14
locator = QuoteLocators .CONTENT_LOCATOR
14
- return self .parent .find_element_by_css_selector ( locator ).text
15
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
15
16
16
17
@property
17
18
def author (self ):
18
19
locator = QuoteLocators .AUTHOR_LOCATOR
19
- return self .parent .find_element_by_css_selector ( locator ).text
20
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
20
21
21
22
@property
22
23
def tags (self ):
Original file line number Diff line number Diff line change
1
+ from selenium .webdriver .common .by import By
1
2
from locators .quote_locators import QuoteLocators
2
3
3
4
@@ -11,12 +12,12 @@ def __repr__(self):
11
12
@property
12
13
def content (self ):
13
14
locator = QuoteLocators .CONTENT_LOCATOR
14
- return self .parent .find_element_by_css_selector ( locator ).text
15
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
15
16
16
17
@property
17
18
def author (self ):
18
19
locator = QuoteLocators .AUTHOR_LOCATOR
19
- return self .parent .find_element_by_css_selector ( locator ).text
20
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
20
21
21
22
@property
22
23
def tags (self ):
Original file line number Diff line number Diff line change
1
+ from selenium .webdriver .common .by import By
1
2
from locators .quote_locators import QuoteLocators
2
3
3
4
@@ -11,12 +12,12 @@ def __repr__(self):
11
12
@property
12
13
def content (self ):
13
14
locator = QuoteLocators .CONTENT_LOCATOR
14
- return self .parent .find_element_by_css_selector ( locator ).text
15
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
15
16
16
17
@property
17
18
def author (self ):
18
19
locator = QuoteLocators .AUTHOR_LOCATOR
19
- return self .parent .find_element_by_css_selector ( locator ).text
20
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
20
21
21
22
@property
22
23
def tags (self ):
Original file line number Diff line number Diff line change 1
1
from typing import List
2
+ from selenium .webdriver .common .by import By
2
3
from selenium .webdriver .support .ui import Select
3
4
4
5
from locators .quotes_page_locators import QuotesPageLocators
@@ -20,8 +21,8 @@ def quotes(self) -> List[QuoteParser]:
20
21
21
22
@property
22
23
def author_dropdown (self ) -> Select :
23
- element = self .browser .find_element_by_css_selector (
24
- QuotesPageLocators .AUTHOR_DROPDOWN
24
+ element = self .browser .find_element (
25
+ By . CSS_SELECTOR , QuotesPageLocators .AUTHOR_DROPDOWN
<
10000
code>25 26
)
26
27
return Select (element )
27
28
Original file line number Diff line number Diff line change
1
+ from selenium .webdriver .common .by import By
1
2
from locators .quote_locators import QuoteLocators
2
3
3
4
@@ -11,12 +12,12 @@ def __repr__(self):
11
12
@property
12
13
def content (self ):
13
14
locator = QuoteLocators .CONTENT_LOCATOR
14
- return self .parent .find_element_by_css_selector ( locator ).text
15
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
15
16
16
17
@property
17
18
def author (self ):
18
19
locator = QuoteLocators .AUTHOR_LOCATOR
19
- return self .parent .find_element_by_css_selector ( locator ).text
20
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
20
21
21
22
@property
22
23
def tags (self ):
Original file line number Diff line number Diff line change 1
1
from typing import List
2
+ from selenium .webdriver .common .by import By
2
3
from selenium .webdriver .support .ui import Select
3
4
4
5
from locators .quotes_page_locators import QuotesPageLocators
@@ -20,15 +21,15 @@ def quotes(self) -> List[QuoteParser]:
20
21
21
22
@property
22
23
def author_dropdown (self ) -> Select :
23
- element = self .browser .find_element_by_css_selector (
24
- QuotesPageLocators .AUTHOR_DROPDOWN
24
+ element = self .browser .find_element (
25
+ By . CSS_SELECTOR , QuotesPageLocators .AUTHOR_DROPDOWN
25
26
)
26
27
return Select (element )
27
28
28
29
@property
29
30
def tags_dropdown (self ):
30
- element = self .browser .find_element_by_css_selector (
31
- QuotesPageLocators .TAG_DROPDOWN
31
+ element = self .browser .find_element (
32
+ By . CSS_SELECTOR , QuotesPageLocators .TAG_DROPDOWN
32
33
)
33
34
return Select (element )
34
35
Original file line number Diff line number Diff line change
1
+ from selenium .webdriver .common .by import By
1
2
from locators .quote_locators import QuoteLocators
2
3
3
4
@@ -11,12 +12,12 @@ def __repr__(self):
11
12
@property
12
13
def content (self ):
13
14
locator = QuoteLocators .CONTENT_LOCATOR
14
- return self .parent .find_element_by_css_selector ( locator ).text
15
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
15
16
16
17
@property
17
18
def author (self ):
18
19
locator = QuoteLocators .AUTHOR_LOCATOR
19
- return self .parent .find_element_by_css_selector ( locator ).text
20
+ return self .parent .find_element ( By . CSS_SELECTOR , locator ).text
20
21
21
22
@property
22
23
def tags (self ):
Original file line number Diff line number Diff line change 1
1
from typing import List
2
+ from selenium .webdriver .common .by import By
2
3
from selenium .webdriver .support .ui import Select
3
4
4
5
from locators .quotes_page_locators import QuotesPageLocators
@@ -20,22 +21,22 @@ def quotes(self) -> List[QuoteParser]:
20
21
21
22
@property
22
23
def author_dropdown (self ) -> Select :
23
- element = self .browser .find_element_by_css_selector (
24
- QuotesPageLocators .AUTHOR_DROPDOWN
24
+ element = self .browser .find_element (
25
+ By . CSS_SELECTOR , QuotesPageLocators .AUTHOR_DROPDOWN
25
26
)
26
27
return Select (element )
27
28
28
29
@property
29
30
def tags_dropdown (self ):
30
- element = self .browser .find_element_by_css_selector (
31
- QuotesPageLocators .TAG_DROPDOWN
31
+ element = self .browser .find_element (
32
+ By . CSS_SELECTOR , QuotesPageLocators .TAG_DROPDOWN
32
33
)
33
34
return Select (element )
34
35
35
36
@property
36
37
def search_button (self ):
37
- return self .browser .find_element_by_css_selector (
38
- QuotesPageLocators .SEARCH_BUTTON
38
+ return self .browser .find_element (
39
+ By . CSS_SELECTOR , QuotesPageLocators .SEARCH_BUTTON
39
40
)
40
41
41
42
def select_author (self , author_name : str ):
You can’t perform that action at this time.
0 commit comments