Error swap/attach the new tab in the browser

Hi all,

I am doing a process, where I open a new window in a web page (in chrome (control + t)), I paste a URL obtained with the href attribute, I do a treatment and I close the page. In order to replicate it, I have made a small process where I have the same error to see if you can help me. The problem is that the robot does not know which page it is on and that’s why it fails and does not find the xpath. Can you help me with this problem? Focus on the new window is the priority.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config"
	scriptlang="groovy">

	<robotics-flow>
		<robot driver="universal" close-on-completion="true"
			start-in-private="false">
			<capability name="SEARCH_ALL_WINDOWS" value="true" />
			<capability name="CLOSE_ALL_WINDOWS" value="false" />
			<script><![CDATA[
				import com.workfusion.studio.rpa.recorder.api.*
				import com.workfusion.studio.rpa.recorder.api.types.*
				import com.workfusion.studio.rpa.recorder.api.custom.*
				import com.workfusion.studio.rpa.recorder.api.internal.representation.*


				def texto = RString.of('YouTube')


				def texto2 = RString.of('')



				enableTypeOnScreen()

				timeouts().pageLoadTimeout(10000, java.util.concurrent.TimeUnit.MILLISECONDS)

				openChrome(UrlOperations.ensureProtocol("www.google.es"))


				switchToExistingWindow(new WindowDescriptor("", "(?i).*\\QChrome\\E.*", false, true).toString(), 10000)
				window().maximize()


				$(byXpath("//input[@name=\'q\']")).setValue(String.valueOf(texto))



				inDesktop {
					sendKeys(StringTransformations.getKeyPressText(28, 13, 10, 0))
				}
				sleep(5000)


				texto2 = RString.of($(byXpath("//a[@href=\"https://www.youtube.com/?gl=ES&hl=es\"]")).getAttribute("href"))



				inDesktop {
					sendKeys(StringTransformations.getHotKeyText(116, 2))
				}
				setClipboardText(texto2 as String)



				inDesktop {
					sendKeys(StringTransformations.getHotKeyText(118, 2))
				}



				inDesktop {
					sendKeys(StringTransformations.getKeyPressText(28, 13, 10, 0))
				}
				sleep(5000)


				switchToExistingWindow(new WindowDescriptor("", "(?i).*\\QYouTube\\E.*", false, true).toString(), 10000)
				window().maximize()

                tabs = new ArrayList(driver().getWindowHandles())                
                switchTo().window(tabs.get(1))

				$(byXpath("//input[@id=\'search\']")).click()



				inDesktop {
					sendKeys(StringTransformations.escapeAutoitText("WorkFusion"))
				}



				inDesktop {
					sendKeys(StringTransformations.getKeyPressText(28, 13, 10, 0))
				}
				sleep(5000)




				putAt("texto", texto)
				putAt("texto2", texto2)
			]]></script>
		</robot>
	</robotics-flow>

	<export include-original-data="true">
		<single-column name="texto"
			value="${texto.toCanonicalRepresentation()}" />
		<single-column name="texto2"
			value="${texto2.toCanonicalRepresentation()}" />
	</export>


</config>

Error:

no such element: Unable to locate element: {“method”:“xpath”,“selector”:"//input[@id=‘search’]"} (Session info: chrome=74.0.3729.131) (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: ‘9.0.0.4’, revision: ‘e6e278acd9’, time: ‘2018-06-19T14:40:11.651Z’ System info: host: ‘BGM8491X283878P’, ip: ‘180.93.238.92’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’ Driver info: org.openqa.selenium.remote.RemoteWebDriver Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=XP, acceptSslCerts=false, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=XP, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab), userDataDir=C:\Users\X283878\AppData\Local\Temp\scoped_dir11508_19708}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, version=74.0.3729.131, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}] Session ID: 6e2a1046c6316c4c4eb58ff33aeab70a *** Element info: {Using=xpath, value=//input[@id=‘search’]} For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: ‘9.0.0.4’, revision: ‘e6e278acd9’, time: ‘2018-06-19T14:40:11.651Z’ System info: host: ‘BGM8491X283878P’, ip: ‘180.93.238.92’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’ Driver info: driver.version: UniversalDriver
07:45:03 [INFO] (Untitled-1_bot_task.xml:74)

How I said… if I create a web page with YouTube the Xpath works. Can I put in the XPath a tab that I want to click? If not… What code could put to focus the YouTube page?

Thank you so much.

Hi @druizvar after opening the new window/tab, you can save the handle of this window in a variable and then switch to it using a custom action

1 Like

Thanks for the fast answer…

For this example works fine, i will try with my code.

1 Like