@@ -36,54 +36,37 @@ import static io.github.seleniumquery.SeleniumQuery.$; // this will allow the sh
36
36
37
37
public class SeleniumQueryExample {
38
38
public static void main (String [] args ) {
39
- // sets Firefox as the driver -- this is optional, if omitted, will default
40
- // to HtmlUnit or whatever you set at the, also optional, config files
41
- //
42
- $. driver(). useFirefox(). withoutJavaScript(); // JS will be disabled!
39
+ // sets Firefox as the driver (this is optional, if omitted, will default to HtmlUnit)
40
+ $. driver(). useFirefox(). withoutJavaScript(); // JavaScript will be disabled!
43
41
44
- $. url(" http://www.google.com/?hl=en" );
42
+ $. url(" http://www.google.com/?hl=en" );
45
43
46
- $(" :text[name='q']" ). val(" selenium" ); // the keys are actually typed
47
- $(" :button:contains('Google Search')" ). click();
44
+ $(" :text[name='q']" ). val(" selenium" ); // the keys are actually typed!
45
+ $(" :button:contains('Google Search')" ). click();
48
46
49
- String resultsText = $(" #resultStats" ). text();
50
- System . out. println(resultsText);
47
+ // Alternatively: $(":text[name='q']").val("selenium").submit();
51
48
52
- // Besides the short syntax and the jQuery behavior you already know,
53
- // other very useful function in seleniumQuery is .waitUntil(),
54
- // handy for dealing with Ajax enabled pages:
55
- //
56
- $(" :input[name='q']" ). waitUntil(). is(" :enabled" );
57
- // The line above waits for no time, as that input is always enabled in google.com
49
+ // Besides the short syntax and the jQuery behavior you already know,
50
+ // other very useful function in seleniumQuery is .waitUntil(),
51
+ // handy for dealing with user-waiting actions (specially in Ajax enabled pages):
52
+ String resultsText = $(" #resultStats" ). waitUntil(). is(" :visible" ). then(). text();
53
+ System . out. println(resultsText);
58
54
59
- $. quit(); // quits the currently used driver (firefox)
55
+ $. quit(); // quits the currently used driver (firefox)
60
56
}
61
57
}
62
58
```
63
- The code above can be found at the sample [ seleniumQuery demos project] ( https://github.com/seleniumQuery/seleniumQuery-demos ) .
59
+ The code above can be found at the [ seleniumQuery demos project] ( https://github.com/seleniumQuery/seleniumQuery-demos ) .
64
60
65
61
To get seleniumQuery's latest snapshot, add this to your ** ` pom.xml ` ** :
66
62
``` xml
67
63
<dependencies >
68
64
<dependency >
69
65
<groupId >io.github.seleniumquery</groupId >
70
66
<artifactId >seleniumquery</artifactId >
71
- <version >0.9.0-SNAPSHOT </version >
67
+ <version >0.9.0</version >
72
68
</dependency >
73
69
</dependencies >
74
- <!-- The repository the snapshots will be downloaded from.
75
- Can either go in your pom.xml or settings.xml -->
76
- <repositories >
77
- <repository >
78
- <id >sonatype-nexus-snapshots</id >
79
- <name >Sonatype Nexus Snapshots</name >
80
- <url >https://oss.sonatype.org/content/repositories/snapshots/</url >
81
- <snapshots >
82
- <enabled >true</enabled >
83
- <updatePolicy >always</updatePolicy >
84
- </snapshots >
85
- </repository >
86
- </repositories >
87
70
```
88
71
89
72
<br >
@@ -164,6 +147,28 @@ String oldStreetz = jQuery("input.street").val();
8000
164
147
jQuery(" input.street" ). val(" 5th St!" );
165
148
```
166
149
150
+ <br >
151
+
152
+ ##seleniumQuery still is Selenium - with "just" a jQuery interface
153
+
154
+ That's why it can work with disabled JavaScript!
155
+
156
+ But there is a more important aspect of that: As our functions yield the same result as if you were using jQuery, remember we always execute them from the user perspective.
157
+ In other words, when you call:
158
+ ``` java
159
+ $(" :input[name='email']" ). val(" seleniumQuery@example.com" );
160
+ ```
161
+
162
+ We don't change the ` value ` attribute directly like jQuery does. We actually do as a user would: We clear the input
163
+ and type, key by key, the string provided as argument!
164
+
165
+ But we go the ** extra mile** : Our ` $().val() ` works even on ` contenteditable ` elements: They don't have ` value ` , but we type
166
+ the text in them, again, key by key, as an user would!
167
+
168
+ ###Always from the user perspective
169
+
170
+ On the same tone, when selecting/checking ` <option> ` s or checkboxes or radios, try not to use ` $().prop("selected", true) ` directly to them.
171
+ Do as an user would: call ` .click() ` !
167
172
168
173
<br >
169
174
0 commit comments