java


Check which value contains property Java WebDriver


I'm almost do NOT know Java, but I'm learning and have to write some tests in it using WebDriver & jUnit :) I have already performed some, looks like:
import org.junit.Assert;
import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class MyTests {
#BeforeClass
public static void allTestsStarted() {
System.out.println("All tests started");
}
#org.junit.Test
public void testImagePresence() throws Exception {
WebDriver driver = null;
try {
driver = WebDriverHelper.create("https://here.goes.path.to.my.site");
WebElement element = driver.findElement(By.className("myImage"));
String imageSrc = element.getAttribute("src");
Assert.assertNotNull(imageSrc);
} finally {
if (driver != null)
driver.quit();
}
}
# and more and more lines like these :)
}
All works fine :) Now I wanna create test that will check which value now contains my property... Maybe it's not clear, example: one element in one moment of time may contains display: block, and other time it may be display: none... So how it's gonna look like in Java? Just interesting is it possible or not, so please... Any help will be greatly appreciated :)
I think you mean "Attributes".
you can get those using getAttribute: e.g element.getAttribute("display");
Allright, since SO has encouraged users to answer our own questions - I'll do it :) All I had to do is simplify my code a bit :) I wrote two CSS rules: .dispBlock { display:block } and .dispNone { display:none } instead inline css and than in test just checked - visible it or not... Looks like:
WebElement el = driver.findElement(By.className("dispBlock"));
Assert.assertEquals(true, el.isDisplayed());
Of course, on page may be a few elements with that class, but as a first step for learning it works perfectly.

Related Links

How enable scroll using scroll composite in gridlayout?
Youtube Video id by using Service account - got error 403 response
Defining AudioFormat in Java on Ubuntu
Where is the method getDriver initialized in java.sql.DriverManager in JAVA?
Issues with Android Studio 1.0.2
How to return Calendar object in Custom Date format
Color picker not in activity [closed]
Error creating table using Hibernate Schema Updater
Tray Icon displayed not properly
“out.println” not working in jsp
Delete specific HTML tags in String
How to mock method parameter in Mockito
Table not found error in h2 using hibernate3
Access Report from p:menuitem
Eclipse commands in java code
Add regex matches together

Categories

HOME
arduino-uno
single-sign-on
youtube-dl
bookshelf.js
spring-cloud-stream
jgroups
umd
ckeditor
alpha
ojdbc
imacros
php-7.1
windows-azure-storage
percona
lombok
workload-scheduler
highlight.js
ef-migrations
plunker
nas
cx-freeze
sqlcipher
sparse-matrix
kannel
fluentvalidation
bluestacks
oracle-fusion-middleware
copying
textmate
code-search-engine
reportbuilder
leading-zero
bootstrapper
mapzen
no-www
sencha-touch-2.3
jsch
taffy
python-webbrowser
celery-task
idisposable
tropo
ifs
capacity
flutterwave
sqldf
gnome-shell-extensions
measures
mathematica-frontend
player
gridview-sorting
multiple-regression
prettytensor
ipconfig
ios4
goose
rtbkit
eclipse-clp
icu4j
feedback
content-length
wyam
angular-leaflet-directive
microbenchmark
php-ci
appfabric-cache
bridge.net
website-monitoring
codeigniter-url
gadt
has-many-through
typeof
sgen
dealloc
concurrent-collections
listings
pushbackinputstream
http-unit
tinn-r
venn-diagram
multipage
enter
cufon
boost-filesystem
qt-jambi
heartbeat
django-tagging
krl
html-input
sproutcore-2
gamma
anti-piracy
gacutil
ubuntu-9.04
data-acquisition

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App