Skip to content

Instantly share code, notes, and snippets.

@gouf
Created April 1, 2016 14:33
Show Gist options
  • Save gouf/c1841b9867f30cac5a9b3780986e8565 to your computer and use it in GitHub Desktop.
Save gouf/c1841b9867f30cac5a9b3780986e8565 to your computer and use it in GitHub Desktop.
selenium であそぶ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="second.html" target="_blank">click</a>
<form action="#" enctype="multipart/form-data">
<input type="file">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="#" onclick="window.close()">close</a>
</body>
</html>
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox # ブラウザ起動
driver.get('http://localhost:3000/index.html')
p driver.find_element(xpath: '//a').click
sleep 1
driver.switch_to.window(driver.window_handles.last)
sleep 1
driver.find_element(xpath: '//a').click
str = '/Test_Path/test.txt'
driver.switch_to.window(driver.window_handles.first)
driver.find_element(xpath: '//form/input').send_keys(str)
sleep 3
driver.quit # ブラウザ終了
# 新しいウィンドウを開くボタン押下
# driver.find_element(:id, "open_new_window_button").click
# 操作対象を新しいウィンドウに切り替える
# driver.switch_to.window(@driver.window_handles.last)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment