code is not working for attaching a file in gmail and sending

rpa

#1

Hi All,

Hope you are doing very well. I have written below code to send an email with an attachment. Same code is runing in local machine, but if i try to run in control tower getting error as “compose element not found”
"Capabilities
[{enablePersistentHover=false, extra.start.in.private=true, extra.remote.browser.driver.address=http://localhost:43809, ie.fileUploadDialogTimeout=3000, platform=WINDOWS, ie.ensureCleanSession=true, ie.browserCommandLineSwitches=-private, requireWindowFocus=true, browserName=internet explorer, takesScreenshot=true, javascriptEnabled=true, unexpectedAlertBehaviour=dismiss, capabilityNodeId=http://127.0.0.1:5000, browserAttachTimeout=0, ie.enableFullPageScreenshot=true, extra.block.images=false, extra.executor.id={run.name=sdsd [2018-04-25 05:32:27] [2018-04-25 06:30:30] [2018-04-25 06:36:39], task.name=mailcheck[2018-04-25 12:28:55], context.path=/workfusion, host.name=http://localhost:8080, run.author.email=wasim.c.akram@accenture.com, run.uuid=40674ffc-a260-4755-b4b2-788d06ad738f, run.author.fullname=Wasim Akram}, ie.forceCreateProcessApi=true, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=true, ignoreZoomSetting=false, extra.parent.browser.capabilities={capabilityNodeId=http://127.0.0.1:5000, extra.block.images=false, extra.start.in.private=true, extra.executor.id={run.name=sdsd [2018-04-25 05:32:27] [2018-04-25 06:30:30] [2018-04-25 06:36:39], task.name=mailcheck[2018-04-25 12:28:55], context.path=/workfusion, host.name=http://localhost:8080, run.author.email=wasim.c.akram@accenture.com, run.uuid=40674ffc-a260-4755-b4b2-788d06ad738f, run.author.fullname=Wasim Akram}, webdriver.remote.sessionid=deb11c97-2dc5-43af-9bd9-24f4041d425a, browserName=desktop, takesScreenshot=true, maximize.on.startup=true, javascriptEnabled=true, version=1.0, platform=WINDOWS}, version=11, proxy={proxyType=direct}, nativeEvents=true, elementScrollBehavior=0, webdriver.remote.sessionid=bfc3688b-3f16-43b7-a452-2f8e020f1910, initialBrowserUrl=http://localhost:43809/, maximize.on.startup=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true}]
Session ID: 20856df45489c95ad08610858e4e0ddabfc3688b-3f16-43b7-a452-2f8e020f1910
*** Element info: {Using=xpath, value=.///text()[normalize-space(.) = “COMPOSE”]/parent::}
at com.freedomoss.crowdcontrol.webharvest.plugin.selenium.RobotPlugin.executePlugin(RobotPlugin.java:187)
at org.webharvest.runtime.processors.WebHarvestPlugin.execute(WebHarvestPlugin.java:125)
at org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:127)
at org.webharvest.runtime.processors.BodyProcessor.execute(BodyProcessor.java:27)
at org.webharvest.runtime.processors.WebHarvestPlugin.executeBody(WebHarvestPlugin.java:246)
at com.freedomoss.crowdcontrol.webharvest.plugin.selenium.RoboticsFlowPlugin.executePlugin(RoboticsFlowPlugin.java:98)
… 17 more
Caused by: org.webharvest.exception.ScriptException:
Config line 21: script block
org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == .///text()[normalize-space(.) = “COMPOSE”]/parent:: (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.27 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.53.0’, revision: ‘35ae25b1534ae328c771e0856c93e187490ca824’, time: ‘2016-03-15 10:43:46’
System info: host: ‘WIN-UK9OALTGU04’, ip: ‘172.31.26.3’, os.name: ‘Windows Server 2012 R2’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘1.8.0_92’
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=false, ie.forceCreateProcessApi=true, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, proxy={proxyType=direct}, nativeEvents=true, ie.ensureCleanSession=true, elementScrollBehavior=0, ie.browserCommandLineSwitches=-private, requireWindowFocus=true, browserName=internet explorer, initialBrowserUrl=http://localhost:43809/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 5fc3703c-8174-4b84-b1aa-ed5383ea9360
*** Element info: {Using=xpath, value=.///text()[normalize-space(.) = “COMPOSE”]/parent::}
Command duration or timeout: 20.57 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.53.0’, revision: ‘35ae25b1534ae328c771e0856c93e187490ca824’, time: ‘2016-03-15 10:43:46’
System info: host: ‘ip-172-31-46-30’, ip: ‘172.31.46.30’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.13.0-117-generic’, java.version: ‘1.8.0_45’
Driver info: com.freedomoss.crowdcontrol.webharvest.selenium.wrapper.RemoteDriverWrapper
Capabilities [{enablePersistentHover=false, extra.start.in.private=true, extra.remote.browser.driver.address=http://localhost:43809, ie.fileUploadDialogTimeout=3000, platform=WINDOWS, ie.ensureCleanSession=true, ie.browserCommandLineSwitches=-private, requireWindowFocus=true, browserName=internet explorer, takesScreenshot=true, javascriptEnabled=true, unexpectedAlertBehaviour=dismiss, capabilityNodeId=http://127.0.0.1:5000, browserAttachTimeout=0, ie.enableFullPageScreenshot=true, extra.block.images=false, extra.executor.id={run.name=sdsd [2018-04-25 05:32:27] [2018-04-25 06:30:30] [2018-04-25 06:36:39], task.name=mailcheck[2018-04-25 12:28:55], context.path=/workfusion, host.name=http://localhost:8080, run.author.email=wasim.c.akram@accenture.com, run.uuid=40674ffc-a260-4755-b4b2-788d06ad738f, run.author.fullname=Wasim Akram}, ie.forceCreateProcessApi=true, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=true, ignoreZoomSetting=false, extra.parent.browser.capabilities={capabilityNodeId=http://127.0.0.1:5000, extra.block.images=false, extra.start.in.private=true, extra.executor.id={run.name=sdsd [2018-04-25 05:32:27] [2018-04-25 06:30:30] [2018-04-25 06:36:39], task.name=mailcheck[2018-04-25 12:28:55], context.path=/workfusion, host.name=http://localhost:8080, run.author.email=wasim.c.akram@accenture.com, run.uuid=40674ffc-a260-4755-b4b2-788d06ad738f, run.author.fullname=Wasim Akram}, webdriver.remote.sessionid=deb11c97-2dc5-43af-9bd9-24f4041d425a, browserName=desktop, takesScreenshot=true, maximize.on.startup=true, javascriptEnabled=true, version=1.0, platform=WINDOWS}, version=11, proxy={proxyType=direct}, nativeEvents=true, elementScrollBehavior=0, webdriver.remote.sessionid=bfc3688b-3f16-43b7-a452-2f8e020f1910, initialBrowserUrl=http://localhost:43809/, maximize.on.startup=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true}]
Session ID: 20856df45489c95ad08610858e4e0ddabfc3688b-3f16-43b7-a452-2f8e020f1910
*** Element info: {Using=xpath, value=.///text()[normalize-space(.) = “COMPOSE”]/parent::}
at org.webharvest.runtime.scripting.GroovyScriptEngine.eval(GroovyScriptEngine.java:138)
at org.webharvest.runtime.processors.ScriptProcessor.execute(ScriptProcessor

"

Please suggest how to rectify the same.
Thank you

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">

    

    <robotics-flow>

        <robot name="bb8" driver="desktop" close-on-completion="true">

            <script> <![CDATA[

            

           	// Copy the file to the RPA machine.

//         s3Path = 'https://s3.amazonaws.com/wf-vr-training/king_details.csv'
//  		filePath = downloadFileOnAgent(s3Path)

            	

          ]]></script>

        </robot>

     

        <robot name="webRobot" driver="chrome" close-on-completion="false" start-in-private="true">

            <script><![CDATA[

            	

            	def loginPage = 'http://mail.google.com'

		        def username = 'wfwasimwf@gmail.com'

		        def password = '*******'

		        def mailSubject = 'Attach PDF'

		        def mailBody = 'This is an RPA message with attached PDF file.'

            	

                timeouts(40 * 1000)

                

                // Login into the mail system            

                open(loginPage)
				
                $('#identifierId').val(username).pressEnter()
                Thread.sleep(3000)
				
                $(byXpath("//*[@id='password']/div[1]/div/div[1]/input")).val(password)

                $('#passwordNext').click()
				
    			Thread.sleep(10000)

    			// Populate new message fields

              
                   $(byXpath("//div[contains(text(),'COMPOSE')]"))
        
                Thread.sleep(3000)         

                $(By.name('to')).val("wasim.c.akram@accenture.com").pressTab()
                Thread.sleep(3000)

                $(by('placeholder', 'Subject')).val(mailSubject).pressTab()
                Thread.sleep(3000)

                $('.editable').val(mailBody).pressEnter()

                Thread.sleep(3000)

                // Start attaching file.

                $(byXpath("//div[@class='a1 aaA aMZ']")).click()

               Thread.sleep(3000)

            ]]></script>

        </robot>

         

        <robot name="r2d2" driver="desktop" close-on-completion="true">

        	<capability name="SEARCH_ALL_WINDOWS" value="true" />

            <script><![CDATA[

            Thread.sleep(3000)

                // Attach file using "upload file" dialog.

                switchTo().window('[CLASS:#32770]')
                Thread.sleep(3000)

                //$('[CLASS:Edit;INSTANCE:1]').sendKeys(filePath)
                $('[CLASS:Edit;INSTANCE:1]').sendKeys("A9R1k3idgg_vvrot6_bak")
                
                Thread.sleep(3000)

                $('[CLASS:Button;INSTANCE:1]').click()

                Thread.sleep(3000)

            ]]></script>

        </robot>

         

        <robot name="webRobot" driver="chrome" close-on-completion="true">

            <script><![CDATA[

            Thread.sleep(3000)

                $(byText('Send')).click() 
                Thread.sleep(3000)
                $(byXpath("//*[@id='link_vsm']")).click()
               
                
//                sleep(3000)
//         driver.findElement(By.id("gbi4m1")).click(); 
//        driver.findElement(By.id("gb_71")).click(); 

//            Thread.sleep(3000)

            ]]></script>

        </robot>

    </robotics-flow>

        

    <export include-original-data="false">   

        <single-column name="rpa_local_file_path" value="${filePath}"/>

    </export>

     

</config>

#2

Hi! One of the possible answer can be: You are facing google account blocks from gmail. In order to solve this problem You can look on our forum topic here.