Seleniumでxpathを使ったログインボタンのクリックができません

3,027 views
Skip to first unread message

Tottoro

unread,
Aug 5, 2020, 3:05:20 AM8/5/20
to 日本Seleniumユーザーコミュニティ

セールスフォースのサイトを例として挙げていますが、どのサイトでもユーザー名、パスワードまでは入力できます。
しかし、ログインボタンを押すことができません。
どなたか、ご指摘お願いします。    

package Demo01;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class salesforce {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");

        WebDriver driver =new ChromeDriver();


        driver.get("http://login.salesforce.com/");
        driver.findElement(By.id("username")).sendKeys("Thisis my first code");
        driver.findElement(By.name("pw")).sendKeys("123456");
        driver.findElement(By.xpath("//*[@id=\'Login\']")).clear();

コンソールの表示は以下の通りです。

Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 14992
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
805, 2020 3:29:43 午後 org.openqa.selenium.remote.ProtocolHandshake createSession
情報: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.InvalidElementStateException: invalid element state

よろしくお願いします。


Tottoro

unread,
Aug 5, 2020, 3:08:29 AM8/5/20
to 日本Seleniumユーザーコミュニティ

driver.findElement(By.xpath("//*[@id=\'Login\']")).clear();
driver.findElement(By.xpath("//*[@id='Login']")).clear();

『\』を外してみましたが、結果は同じで、ログインボタンが押されません。
2020年8月5日水曜日 16時05分20秒 UTC+9 Tottoro:

Mieko Furuhashi

unread,
Aug 5, 2020, 3:12:27 AM8/5/20
to Tottoro, 日本Seleniumユーザーコミュニティ
org.openqa.selenium.InvalidElementStateException: invalid element state
というのは要素が指定されたメソッドを実行できない状態にあるということを示しています。
clear()はテキストフィールドなどの入力値を消すということなのでボタンなどには実行できないです。ボタンを押すのであればclick()では?

--
このメールは Google グループのグループ「日本Seleniumユーザーコミュニティ」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには seleniumjp+...@googlegroups.com にメールを送信してください。
このディスカッションをウェブ上で閲覧するには https://groups.google.com/d/msgid/seleniumjp/fd32707c-e13f-46a9-9d56-d5e680d349cao%40googlegroups.com にアクセスしてください。


--
Mieko Furuhashi
古橋美恵子

Tottoro

unread,
Aug 5, 2020, 3:19:39 AM8/5/20
to 日本Seleniumユーザーコミュニティ
ありがとうございます、解決することができました!

2020年8月5日水曜日 16時12分27秒 UTC+9 Mieko Furuhashi:
このグループから退会し、グループからのメールの配信を停止するには selen...@googlegroups.com にメールを送信してください。
このディスカッションをウェブ上で閲覧するには https://groups.google.com/d/msgid/seleniumjp/fd32707c-e13f-46a9-9d56-d5e680d349cao%40googlegroups.com にアクセスしてください。
Reply all
Reply to author
Forward
0 new messages