@@ -11,16 +11,17 @@ internal class NotionWebsitePuppeteer
11
11
private IWebDriver _driver ;
12
12
private readonly string _username ;
13
13
private readonly string _password ;
14
+ private readonly bool _debugMode ;
14
15
15
16
public string MailHost { get ; set ; }
16
17
public string MailUser { get ; set ; }
17
18
public string MailPassword { get ; set ; }
18
- public NotionWebsitePuppeteer ( string seleniumHost , string notionUsername , string notionPassword )
19
+ public NotionWebsitePuppeteer ( string seleniumHost , string notionUsername , string notionPassword , bool debugMode = false )
19
20
{
20
21
_seleniumHost = seleniumHost ;
21
22
_username = notionUsername ;
22
23
_password = notionPassword ;
23
-
24
+ _debugMode = debugMode ;
24
25
}
25
26
26
27
private void Login ( )
@@ -78,7 +79,7 @@ bool FirstLoginStep()
78
79
try
79
80
{
80
81
IWebElement loginCodeBtn =
81
- _driver . FindElement ( By . XPath ( "//form//div [contains(text(), 'Continue with login code')]" ) ) ;
82
+ _driver . FindElement ( By . XPath ( "//form//label [contains(text(), 'Verification code')]" ) ) ;
82
83
if ( loginCodeBtn != null )
83
84
{
84
85
needsLoginCode = true ;
@@ -97,8 +98,14 @@ bool FirstLoginStep()
97
98
var options = new ChromeOptions ( ) ;
98
99
options . AddArgument ( "--headless=new" ) ;
99
100
100
- _driver = new RemoteWebDriver ( new Uri ( _seleniumHost ) , options ) ;
101
- //_driver = new ChromeDriver();
101
+ if ( _debugMode )
102
+ {
103
+ _driver = new ChromeDriver ( ) ;
104
+ }
105
+ else
106
+ {
107
+ _driver = new RemoteWebDriver ( new Uri ( _seleniumHost ) , options ) ;
108
+ }
102
109
WebDriverWait wait = new WebDriverWait ( _driver , TimeSpan . FromSeconds ( 120 ) ) ;
103
110
104
111
bool needsLoginCode = FirstLoginStep ( ) ;
@@ -153,26 +160,33 @@ public void TriggerExport(List<string> workspaceSlug)
153
160
154
161
foreach ( string ws in workspaceSlug )
155
162
{
156
- Thread . Sleep ( 10000 ) ;
157
- Console . WriteLine ( $ "Navigate to workspace { ws } ...") ;
158
- _driver . Navigate ( ) . GoToUrl ( $ "https://notion.so/{ ws } ") ;
159
-
160
- Thread . Sleep ( 5000 ) ;
161
- Console . WriteLine ( "Navigating to Export button..." ) ;
162
- IWebElement nextBtn = _driver . FindElement ( By . XPath ( "//nav//div[contains(text(), 'Settings')]" ) ) ;
163
- nextBtn . Click ( ) ;
164
-
165
- Thread . Sleep ( 3000 ) ;
166
- _driver . FindElement ( By . XPath ( "//div[text() = 'Settings']" ) ) . Click ( ) ;
167
-
168
- Thread . Sleep ( 3000 ) ;
169
- _driver . FindElement ( By . XPath ( "//div[text() = 'Export all workspace content']" ) ) . Click ( ) ;
170
-
171
- Thread . Sleep ( 3000 ) ;
172
- Console . WriteLine ( "Trigger Export..." ) ;
173
- _driver . FindElement ( By . XPath ( "//div[text() = 'Export']" ) ) . Click ( ) ;
163
+ try
164
+ {
165
+ Thread . Sleep ( 10000 ) ;
166
+ Console . WriteLine ( $ "Navigate to workspace { ws } ...") ;
167
+ _driver . Navigate ( ) . GoToUrl ( $ "https://notion.so/{ ws } ") ;
168
+
169
+ Thread . Sleep ( 5000 ) ;
170
+ Console . WriteLine ( "Navigating to Export button..." ) ;
171
+ IWebElement nextBtn = _driver . FindElement ( By . XPath ( "//nav//div[contains(text(), 'Settings')]" ) ) ;
172
+ nextBtn . Click ( ) ;
173
+
174
+ Thread . Sleep ( 3000 ) ;
175
+ _driver . FindElement ( By . XPath ( "//div[@class='notion-space-settings']//div[text() = 'Settings']" ) ) . Click ( ) ;
176
+
177
+ Thread . Sleep ( 3000 ) ;
178
+ _driver . FindElement ( By . XPath ( "//div[@class='notion-space-settings']//div[text() = 'Export all workspace content']" ) ) . Click ( ) ;
179
+
180
+ Thread . Sleep ( 3000 ) ;
181
+ Console . WriteLine ( "Trigger Export..." ) ;
182
+ _driver . FindElement ( By . XPath ( "//div[@class='notion-dialog']//div[text() = 'Export']" ) ) . Click ( ) ;
174
183
175
- Console . WriteLine ( $ "Export running for { ws } ") ;
184
+ Console . WriteLine ( $ "Export running for { ws } ") ;
185
+ }
186
+ catch ( Exception ex )
187
+ {
188
+ Console . WriteLine ( $ "Error triggering export for workspace { ws } : { ex . Message } ") ;
189
+ }
176
190
}
177
191
178
192
// sleeping to let export init
0 commit comments