![redsjavahouse1591357_1280.jpg](https://steemitimages.com/0x0/https://files.steempeak.com/file/steempeak/june0620/DKldjbG3-reds-java-house-1591357_1280.jpg) image source: [pixabay](https://pixabay.com/photos/red-s-java-house-eatery-cafe-1591357/0) --- 接下来我们给元素加点action吧。除上期使用过的click()外详细的再探索一下别的action。 首先呢,用sendKeys(), click(), submit()函数登录STEEMIT并写贴。当然,不点击保存按钮 哈哈(希望在不远的将来AI帮我们写贴) #### 分析 1. 用 By.linkText()获取登录按钮并 click() 2. By.name()可以查找用户名及密码输入框并用 sendKeys()输入文本 3. 登录部分都包含在form元素,所以可以用 submit()来简单提交 4. 搜索了撰写按钮,发现有两按钮,一个显示在页面,另一个不显示。那么可以用 isDisplayed()来判断按钮。 5. 用 sendKeys()往编辑器输入文本。**一般的 String和 Selenium提供的 Keys enum都可以用到参数。如果想加两个以上键盘按键则可以用 Keys.chord()。再一个,参数为可变参数,可以输入多个参数。** ``` package com.steem.webatuo; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; public class Steemit { public static void main(String[] args) throws InterruptedException { WebDriverManager.chromedriver().setup(); WebDriver driver = new ChromeDriver(); driver.get("https://steemit.com/@june0620/feed"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); //Click the login button driver.findElement(By.linkText("로그인")).click(); // type id driver.findElement(By.name("username")).sendKeys("june0620"); // type pw and submit WebElement pw = driver.findElement(By.name("password")); pw.sendKeys(Password.getPw()); pw.submit(); Thread.sleep(5000); // Click the write Button List<WebElement> writeBtns = driver.findElements(By.xpath("//a[@href='/submit.html']")); for(WebElement writeBtn : writeBtns) { if(writeBtn.isDisplayed()) { writeBtn.click(); Thread.sleep(2000); //type Text and Keys WebElement editor = driver.findElement(By.xpath("//textarea[@name='body']")); String keys = Keys.chord(Keys.LEFT_SHIFT, Keys.ENTER); editor.sendKeys("hello!! world", keys, "hello!!! STEEMIT", Keys.ENTER, "안녕, 스팀잇", Keys.ENTER, "你好!似提姆"); break; } } Thread.sleep(5000); driver.quit(); } } ``` #### 视频: [https://youtu.be/FVL4VsU6qiM](https://youtu.be/FVL4VsU6qiM) #### ETC. selenium 的 Actions 类可以给action添加更多的色彩。 Actions 类包括 clickAndHold, contextClick, doubleClick, dragAndDrop, moveToElemen 等函数。👇 ![image.png](https://steemitimages.com/0x0/https://files.steempeak.com/file/steempeak/june0620/o9WiBWKq-image.png)
post_id | 83,866,061 |
---|---|
author | june0620 |
permlink | java-5-web-automation-5-controlling-steemit-web-pages-with-selenium-3-actions-cn |
category | cn |
json_metadata | {"app":"steempeak\/2.2.8","format":"markdown","tags":["cn","cn-stem","mini","steemstem","zzan","palnet","liv","lifestyle","dblog","java"],"users":["june0620","href","name"],"links":["https:\/\/pixabay.com\/photos\/red-s-java-house-eatery-cafe-1591357\/0","https:\/\/youtu.be\/FVL4VsU6qiM"],"image":["https:\/\/files.steempeak.com\/file\/steempeak\/june0620\/DKldjbG3-reds-java-house-1591357_1280.jpg","https:\/\/files.steempeak.com\/file\/steempeak\/june0620\/o9WiBWKq-image.png"]} |
created | 2020-01-29 03:41:18 |
last_update | 2020-01-29 03:41:18 |
depth | 0 |
children | 4 |
net_rshares | 22,468,140,471,647 |
last_payout | 2020-02-05 03:41:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 3.064 SBD |
curator_payout_value | 2.492 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 2,533 |
author_reputation | 219,336,602,045,061 |
root_title | "[JAVA 5#] [Web Automation 5#] Controlling STEEMIT web pages with Selenium #3 Actions [CN]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
gerber | 0 | 323,221,706,103 | 6% | ||
daan | 0 | 186,218,698,579 | 3% | ||
slowwalker | 0 | 187,624,668,978 | 13% | ||
exyle | 0 | 351,357,732,378 | 5% | ||
magicmonk | 0 | 1,155,967,929,253 | 100% | ||
tumutanzi | 0 | 6,731,715,931 | 50% | ||
steemitboard | 0 | 17,021,778,505 | 1% | ||
coldhair | 0 | 760,644,794 | 50% | ||
rycharde | 0 | 1,914,247,471 | 4.5% | ||
allsale | 0 | 387,059,407,140 | 100% | ||
virus707 | 0 | 3,287,655,465,387 | 19% | ||
ew-and-patterns | 0 | 114,376,619,162 | 8% | ||
techken | 0 | 16,781,394 | 0.42% | ||
khaiyoui | 0 | 958,477,107,188 | 25% | ||
smartdeveloper | 0 | 136,287,678 | 42% | ||
perthmint | 0 | 220,246,745 | 47% | ||
kimzwarch | 0 | 8,055,722,560 | 4% | ||
accelerator | 0 | 81,865,438,909 | 4.5% | ||
june0620 | 0 | 1,356,289,838,036 | 100% | ||
xiaoshancun | 0 | 11,583,792,642 | 100% | ||
minloulou | 0 | 2,318,196,141 | 10% | ||
lindalex | 0 | 576,596,563 | 50% | ||
blockbrothers | 0 | 70,258,056,336 | 2.5% | ||
cnbuddy | 0 | 1,917,072,620,617 | 100% | ||
itchyfeetdonica | 0 | 530,589,528,075 | 100% | ||
jim888 | 0 | 423,711,674,400 | 94% | ||
stupid | 0 | 647,287,236 | 40% | ||
mehta | 0 | 69,471,725,174 | 40% | ||
suhunter | 0 | 955,971,356 | 50% | ||
piotrgrafik | 0 | 11,639,842,995 | 4.8% | ||
udabeu | 0 | 13,424,279,098 | 44% | ||
marsswim | 0 | 90,122,253,715 | 51% | ||
investprosper | 0 | 803,195,343 | 2.34% | ||
cadawg | 0 | 18,703,253,996 | 4.2% | ||
maikuraki | 0 | 2,836,496,858 | 19% | ||
earlmonk | 0 | 577,172,259 | 5% | ||
bestboom | 0 | 33,240,548,739 | 6% | ||
tokepengsiribe | 0 | 11,568,037,864 | 100% | ||
stmdev | 0 | 82,004,010 | 1% | ||
lucky2015 | 0 | 452,629,723,708 | 100% | ||
gghite | 0 | 426,225,513,357 | 50% | ||
jaydih | 0 | 393,059,716,384 | 11% | ||
andrewma | 0 | 10,193,271,953 | 50% | ||
camillesteemer | 0 | -69,835,196 | -10% | ||
pilimili | 0 | 518,115,688 | 95% | ||
loveecho | 0 | 86,852,142,731 | 11% | ||
wanggang | 0 | 150,971,841,928 | 20% | ||
pagliozzo | 0 | 18,014,212,003 | 20% | ||
teamvn | 0 | 17,220,315,810 | 38.72% | ||
harkar | 0 | 83,097,715,339 | 20% | ||
dlike | 0 | 232,179,496,756 | 3.3% | ||
triptolemus | 0 | 23,785,022,009 | 6% | ||
changxiu | 0 | 4,793,217,527 | 50% | ||
laissez-faire | 0 | 96,050,175 | 100% | ||
pet.society | 0 | 20,303,295,932 | 5% | ||
cherryzz | 0 | 190,919,079,072 | 50% | ||
djusti | 0 | 1,809,054,845,600 | 100% | ||
nineteensixteen | 0 | 609,876,627,333 | 100% | ||
wherein | 0 | 2,053,848,942,155 | 48% | ||
sindong | 0 | 757,039,285,754 | 100% | ||
steemfriends | 0 | 4,160,890,172 | 100% | ||
swiftcash | 0 | 22,392,824,417 | 5% | ||
cyberrn | 0 | 1,325,629,302,299 | 30% | ||
primeradue | 0 | 5,932,642,479 | 6% | ||
permaculturedude | 0 | 1,136,302,785 | 3% | ||
fi2eedom | 0 | 5,965,724,094 | 70% | ||
tina3721 | 0 | 4,836,762,516 | 50% | ||
andyhsia | 0 | 6,460,886,352 | 100% | ||
jjm13 | 0 | 17,801,156,977 | 19% | ||
mustard-seed | 0 | 34,645,672,493 | 11% | ||
fsm-liquid | 0 | 13,888,812,774 | 5% | ||
zzan.co3 | 0 | 481,317,666 | 100% | ||
zzan.co17 | 0 | 0 | 45% | ||
triplea.bot | 0 | 2,220,117,836 | 5% | ||
steem.leo | 0 | 169,811,041,607 | 5.7% | ||
leo.voter | 0 | 581,059,932,131 | 4.68% | ||
condeas.pal | 0 | 317,011,897 | 44% | ||
cn-pal | 0 | 217,552,420 | 2% | ||
chrono.leo | 0 | 0 | 2.34% | ||
freddio.sport | 0 | 45,375,982,533 | 10% | ||
mapxv | 0 | 32,143,594,959 | 3.6% | ||
sct.krwp | 0 | 67,167,488,590 | 0.1% | ||
leo.syndication | 0 | 2,786,399,299 | 6% | ||
maxuva | 0 | 2,663,199,346 | 4.5% | ||
maxuvb | 0 | 2,937,691,932 | 4.5% | ||
maxuvc | 0 | 2,951,726,649 | 4.5% | ||
maxuvd | 0 | 2,669,495,125 | 4.5% | ||
maxuve | 0 | 16,182,261,191 | 3.6% | ||
sqljoker | 0 | 32,359,601 | 2% | ||
therealyme | 0 | 11,446,685,246 | 4.5% | ||
thebilpcointrain | 0 | 16,141,846 | 1% | ||
bilpcoin.pay | 0 | 129,065,838 | 1% | ||
cnbuddy-reward | 0 | 595,703,208,782 | 100% | ||
dblogbasicincome | 0 | 79,309,326 | 7% | ||
real3earch | 0 | 9,228,021,495 | 100% | ||
unpopular | 0 | 30,404,282,482 | 40% | ||
we-together | 0 | 471,417,874,905 | 11% | ||
dblogvoter | 0 | 73,312,835 | 1.95% | ||
samotrader | 0 | 0 | 0.1% | ||
tonystarkalive | 0 | 28,796,680 | 2% | ||
reward.tier2 | 0 | 1,735,917,618 | 100% | ||
bilpcoinpower | 0 | 246,538,828 | 10% |
你今天过的开心吗?[欢迎在steemauto里设置跟赞 @cnbuddy](https://steemit.com/cn/@shenchensucc/6y3bap-cnbuddy-cn) 给整个cn区点赞倘若你想让我隐形,请回复“取消”。
post_id | 83,866,339 |
---|---|
author | cnbuddy |
permlink | re-june0620-java-5-web-automation-5-controlling-steemit-web-pages-with-selenium-3-actions-cn-20200129t035802798z |
category | cn |
json_metadata | {} |
created | 2020-01-29 03:58:03 |
last_update | 2020-01-29 03:58:03 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-02-05 03:58:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 119 |
author_reputation | -1,405,328,253,928 |
root_title | "[JAVA 5#] [Web Automation 5#] Controlling STEEMIT web pages with Selenium #3 Actions [CN]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Congratulations @june0620! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) : <table><tr><td><img src="https://steemitimages.com/60x70/http://steemitboard.com/@june0620/votes.png?202001290612"></td><td>You distributed more than 16000 upvotes. Your next target is to reach 17000 upvotes.</td></tr> </table> <sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@june0620) and compare to others on the [Steem Ranking](https://steemitboard.com/ranking/index.php?name=june0620)_</sub> <sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub> To support your work, I also upvoted your post! ###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
post_id | 83,869,161 |
---|---|
author | steemitboard |
permlink | steemitboard-notify-june0620-20200129t070202000z |
category | cn |
json_metadata | {"image":["https:\/\/steemitboard.com\/img\/notify.png"]} |
created | 2020-01-29 07:02:03 |
last_update | 2020-01-29 07:02:03 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-02-05 07:02:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 899 |
author_reputation | 38,705,954,145,809 |
root_title | "[JAVA 5#] [Web Automation 5#] Controlling STEEMIT web pages with Selenium #3 Actions [CN]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
!thumbup 恭喜你!您的这篇文章入选 @justyy 今日 (2020-01-30) 榜单 [【优秀的文章】](https://steemit.com/cn/@justyy/--daily-cn-updates-cncnpower-downyy2020-01-30), 回复本条评论24小时内领赏,点赞本评论将支持 @dailychina 并增加将来您的奖赏。 @justyy 是CN区的见证人,[请支持他,给他投票](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=justyy),或者设置justyy为[见证人代理](https://v2.steemconnect.com/sign/account-witness-proxy?proxy=justyy&approve=1)。感谢!@justyy的主要贡献:https://steemyy.com Congratulations! This post has been selected by @justyy as today's (2020-01-30) [【Good Posts】](https://steemit.com/cn/@justyy/--daily-cn-updates-cncnpower-downyy2020-01-30), Steem On! Reply to this message in 24 hours to get rewards. Upvote this comment to support the @dailychina and increase your future rewards! ^_^ [SteemIt 工具、API接口、机器人和教程](https://steemyy.com/steemit-tools/) [SteemIt Tools, Bots, APIs and Tutorial](https://SteemYY.com)<hr> If you believe what I am doing, please consider a spare vote voting me [here](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=justyy), thank you very much indeed. @justyy - the author of https://SteemYY.com and I have been a Steem Witness for [more than a year now.](https://steemit.com/witness-category/@justyy/one-year-winessversary-a-great-start)
post_id | 83,909,179 |
---|---|
author | dailychina |
permlink | re-java-5-web-automation-5-controlling-steemit-web-pages-with-selenium-3-actions-cn-20200130t080159 |
category | cn |
json_metadata | {} |
created | 2020-01-30 08:02:00 |
last_update | 2020-01-30 08:02:00 |
depth | 1 |
children | 1 |
net_rshares | 307,700,126,723 |
last_payout | 2020-02-06 08:02:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.024 SBD |
curator_payout_value | 0.023 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 1,249 |
author_reputation | 50,118,723,362,727 |
root_title | "[JAVA 5#] [Web Automation 5#] Controlling STEEMIT web pages with Selenium #3 Actions [CN]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
justyy | 0 | 251,148,702,698 | 8% | ||
happyukgo | 0 | 494,941,492 | 25% | ||
superbing | 0 | 8,361,510,792 | 25% | ||
dailyfortune | 0 | 33,219,480 | 25% | ||
dailystats | 0 | 18,987,746,967 | 25% | ||
dailychina | 0 | 17,633,267,045 | 25% | ||
turtlegraphics | 0 | 3,118,063,201 | 25% | ||
witnesstools | 0 | 3,006,349,321 | 25% | ||
ilovecoding | 0 | 2,983,214,845 | 25% | ||
steemfuckeos | 0 | 1,933,110,882 | 25% | ||
cplusplus | 0 | 0 | 25% | ||
justsoso | 0 | 0 | 25% |
谢谢~
post_id | 83,909,240 | ||||||
---|---|---|---|---|---|---|---|
author | june0620 | ||||||
permlink | re-dailychina-2020130t1755543z | ||||||
category | cn | ||||||
json_metadata | {"tags":["esteem"],"app":"esteem\/2.2.3-mobile","format":"markdown+html","community":"esteem.app"} | ||||||
created | 2020-01-30 08:05:54 | ||||||
last_update | 2020-01-30 08:05:54 | ||||||
depth | 2 | ||||||
children | 0 | ||||||
net_rshares | 318,470,371,596 | ||||||
last_payout | 2020-02-06 08:05:54 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.025 SBD | ||||||
curator_payout_value | 0.024 SBD | ||||||
pending_payout_value | 0.000 SBD | ||||||
promoted | 0.000 SBD | ||||||
body_length | 3 | ||||||
author_reputation | 219,336,602,045,061 | ||||||
root_title | "[JAVA 5#] [Web Automation 5#] Controlling STEEMIT web pages with Selenium #3 Actions [CN]" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 SBD | ||||||
percent_steem_dollars | 10,000 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
justyy | 0 | 250,068,066,466 | 8% | ||
happyukgo | 0 | 608,228,695 | 30% | ||
superbing | 0 | 10,110,336,701 | 30% | ||
dailyfortune | 0 | 50,520,591 | 30% | ||
dailystats | 0 | 22,945,859,021 | 30% | ||
dailychina | 0 | 21,309,627,543 | 30% | ||
turtlegraphics | 0 | 3,776,719,227 | 30% | ||
witnesstools | 0 | 3,641,781,008 | 30% | ||
ilovecoding | 0 | 3,613,837,061 | 30% | ||
steemfuckeos | 0 | 2,345,395,283 | 30% | ||
cplusplus | 0 | 0 | 30% | ||
justsoso | 0 | 0 | 30% |