私はセレンを初めて使っています。私はgoogleで私の名前を検索していたし、結果から私は1つのリンクを選択したい。 コードは次のとおりです。セレン:Google検索に表示されるサイトのリストからサイトを選択するにはどうすればよいですか?
public class linkedin {
public static void main(String[] args)
{
ChromeOptions opt= new ChromeOptions();
System.setProperty("webdriver.chrome.driver","path");
WebDriver d = new ChromeDriver(opt);
opt.addArguments("--start-maximized");
d.get("http://www.google.com");
String title=d.getTitle();
System.out.println(title);
WebElement myDynamicElement = (new WebDriverWait(d, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("gs_htif0")));
WebElement btnNew = (new WebDriverWait(d, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("_fZl")));
//WebElement searc = (new WebDriverWait(d, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[contains(text(),'Neethu Raghavan | LinkedIn')]")));
WebElement searc=(new WebDriverWait(d,10).until(ExpectedConditions.elementToBeClickable(By.linkText("Neethu Raghavan | LinkedIn"))));
Actions act= new Actions(d);
act.moveToElement(myDynamicElement).sendKeys("Neethu Raghavan");
act.perform();
act.moveToElement(btnNew).click();
act.perform();
act.moveToElement(searc).click();
act.perform();
}
}
それがうまく機能し、結果が来るの検索ティル。しかしその後、何も起こらない。
私が手にエラーがある:
Exception in thread "main" org.openqa.selenium.TimeoutException:
Expected condition failed: waiting for element to be clickable: By.linkText: Neethu Raghavan | LinkedIn (tried for 10 second(s) with 500 MILLISECONDS interval)
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'INENRAGHAN1L1C', ip: '10.171.40.246', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=C:\Users\raghan1\AppData\Local\Temp\scoped_dir19884_11542}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 9e89b95716b724c5d5e06751ce1aaf5d
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:265)
at linkedin.main(linkedin.java:31)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"link text","selector":"Neethu Raghavan | LinkedIn"}
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 46 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'INENRAGHAN1L1C', ip: '10.171.40.246', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=C:\Users\raghan1\AppData\Local\Temp\scoped_dir19884_11542}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 9e89b95716b724c5d5e06751ce1aaf5d
*** Element info: {Using=link text, value=Neethu Raghavan | LinkedIn}
at sun.reflect.GeneratedConstructorAccessor8.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:425)
at org.openqa.selenium.By$ByLinkText.findElement(By.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:41)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:651)
at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:644)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:238)
Neethu、あなたが試みた方法よりも問題を解決する方がずっと簡単です。 get(google.com)、sendkeys()、待ち、クリック。本当にアクションの必要はありません! –
結果が表示されていると述べました。しかし、あなたの名前を含むテキストとのリンクを待っている前の行からエラーが出ています。 – Grasshopper