Selenium close_fds - selenium

Hello I am trying to run the python script below
from selenium import webdriver
driver=webdriver.Chrome('C:\\Users\\Julian\\Downloads\\chromedriver_win32\\chromedriver.exe')
driver.get('https://www.youtube.com')
Upon Running it I am taken to a file named service.py and pointed to the the following
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,d
close_fds=(platform.system() != 'Windows'),
stdout=self.log_file,
stderr=self.log_file,
stdin=PIPE)
The particular line highlighted
close_fds=(platform.system() != 'Windows'),
Can someone point me in the direction of what I am supposed to do or change? Any help is strongly appreciated!

I just had to remove the d. Must have typed it by accident.

Related

Error with win32com.client.GetObject when connecting to SAP GUI

Dears,
first of all this is the first time I ask a question on Stackoverflow so forgive me if I'm not following the right way to do this.
I kindly ask for your help as I'm facing an issue with win32com.
I'm trying to connect to SAP GUI in order to automate certain tasks.
import win32com.client
SapGuiAuto = win32com.client.GetObject('SAPGUI')
I get the following error (until yesterday everything was working fine..):
Traceback (most recent call last):
File "C:/Users/xxxxx/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/PySAPscript.py", line 157, in <module>
SAP_OP()
File "C:/Users/xxxxx/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/PySAPscript.py", line 18, in SAP_OP
SapGuiAuto = win32com.client.GetObject('SAPGUI')
File "C:\Users\xxxxx\PycharmProjects\yyyyyy\venv\lib\site-packages\win32com\client\__init__.py", line 72, in GetObject
return Moniker(Pathname, clsctx)
File "C:\Users\xxxxxx\PycharmProjects\yyyyyyy\venv\lib\site-packages\win32com\client\__init__.py", line 87, in Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
pywintypes.com_error: (-2147221020, 'Invalid syntax.', None, None)
I've found some documentation about this issue which suggests using pythoncom.CoInitialize():
Using win32com with multithreading
However I can't figure out how to use this function for my purpose.
Thank you for your help!
Considering, that you have variables (SAP_Path, SAP_system_id, SAP_group) or (SAP_Path,
SAP_sid, SAP_instance_no) instead...
shell = win32com.client.Dispatch("WScript.Shell")
call(SAP_Path + " /R/" + SAP_system_id + "/G/" + SAP_group)
OR: call(SAP_Path + " " + SAP_sid + " " + SAP_instance_no)
sap_gui_obj = win32com.client.GetObject("SAPGUI")
application = sap_gui_obj.GetScriptingEngine
connection = application.children(application.connections.count - 1)
session = connection.children(0)
session.findById("wnd[0]").maximize()
Then connect to your base.
I also encountered this problem recently.
The startup permissions of sap and python are not the same.
For example, both of these should be run with administrator rights, or run with ordinary user rights.
I do not guarantee that this method will solve your problem, but you can try :)
I had the same issue when trying to run SAP GUI Script triggered from Flask (desktop) application. Solution that works for me is to embrace the code operating with SAP GUI with pythoncom.CoInitialize() and pythoncom.CoUinitialize() statements:
def display_document():
import win32com.client
import pythoncom
pythoncom.CoInitialize()
sap_gui = win32com.client.GetObject("SAPGUI")
sap_app = sap_gui.GetScriptingEngine
sap_conn = sap_app.Children(0)
sap_session = sap_conn.Children(0)
sap_session.StartTransaction("FB03")
pythoncom.CoUninitialize()

How to get an edge's id using TraCi?

I'm using a python code with the traci library to know if there are any vehicles near a certain distance to a chosen vehicle, to test a solution I'm trying to implement I need to know a vehicle's current edge.
I'm on Ubuntu 18.04.3 LTS, using sublime to edit the code and the os, sys, optparse, subprocess, random, math libraries. I've tried using getLaneId and getEdgeId, the last one is not in the documentation but I tough I've seen it somewhere and tried to test it.
. Another option that i had was using getNeighbors but i didn't know exactly how to use it and it returned the same error message as the previous commands.
def run():
step = 0
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
print(step)
print(distancia("veh1","veh0"))
step += 1
if step > 2:
print(traci.vehicle.getLaneId("veh0"))
traci.close()
sys.stdout.flush()
All of them returned the following error message : AttributeError: VehicleDomain instance has no attribute 'getLaneId'. But I think the vehicle domain has indeed the getLaneId attribute since it is in the documentation: https://sumo.dlr.de/pydoc/traci._vehicle.html#VehicleDomain-getSpeed.
I was expecting it to return the edge's id. Please I need help with this problem. Thank you in advance.
The TraCI command for edgeID can be found in the _vehicle.VehicleDomain module. The syntax is as follows:
traci._vehicle.VehicleDomain.getRoadID(self, vehicleID)
It needs to be getLaneID with a capital D.

selenium.common.exceptions.InvalidSelectorException using Selenium in python 3.7

I want to use selenium to automate the process from open a specific website to log in to search for particular articles. Few of the steps I could do it but facing error in 'sign in' step.
from selenium import webdriver
from selenium.webdriver.common.by import By
base = 'https://www.wsj.com'
url = 'https://www.wsj.com/search/term.html?KEYWORDS=cybersecurity&min-date=2018/04/01&max-date=2019/03/31&isAdvanced=true&daysback=90d&andor=AND&sort=date-desc&source=wsjarticle,wsjpro&page=1'
browser = webdriver.Safari(executable_path='/usr/bin/safaridriver')
browser.get(url)
browser.find_element_by_id('editions-select').click()
browser.find_element_by_id('na,us').click()
browser.find_element(By.XPATH, '//button[#type="button"],[contain(.,"Sign In")]').click()
browser.find_element_by_id('username').send_keys('**#&^&#$##$')
browser.find_element_by_id('password').send_keys('###$%%**')
browser.find_element_by_id('basic-login').click()
browser.find_element_by_id('masthead-container').click()
browser.find_element_by_id('searchInput').send_keys('cybersecurity')
browser.find_element_by_name('ADVANCED SEARCH').click()
browser.find_element_by_id('dp1560924131783').send_keys('2018/04/01')
browser.find_element_by_id('dp1560924131784').send_keys('2019/03/31')
browser.find_element_by_id('wsjblogs').click()
browser.find_element_by_id('wsjvideo').click()
browser.find_element_by_id('interactivemedia').click()
browser.find_element_by_id('sitesearch').click()
The code is working till this line:
browser.find_element_by_id('na,us').click()
But after that it is showing error in this line:
browser.find_element(By.XPATH, '//button[#type="button"],[contain(.,"Sign In")]').click()
The error message says​:
selenium.common.exceptions.InvalidSelectorException: Message:
What is wrong is my code?
This error message...
selenium.common.exceptions.InvalidSelectorException
...implies that the XPath expression was not a valid one.
However, it seems you were close. You need to replace:
'//button[#type="button"],[contain(.,"Sign In")]'
and join the two condition with and operator as follows:
"//button[#type='button' and contains(.,'Sign In')]"

Changing java heapsizes for a websphere server using websphere and wsadminlib.py

Im trying to call a command from wsadminlib.py to change the initialHeapSize and the maximumHeapSize in a script. But unfortunately my jython (and general scripting knowledge) is still total newbie.
Im using the call
#Change Java Heap Size
setJvmProperty(nodeName,serverName,maximumHeapsize -2048 ,initialHeapSize -2048)
Which should relate to the command in the wsadminlib.py library
def setJvmProperty(nodename,servername,propertyname,value):
"""Set a particular JVM property for the named server
Some useful examples:
'maximumHeapSize': 512 ,
'initialHeapSize':512,
'verboseModeGarbageCollection':"true",
'genericJvmArguments':"-Xgcpolicy:gencon -Xdump:heap:events=user -Xgc:noAdaptiveTenure,tenureAge=8,stdGlobalCompactToSatisfyAllocate -Xconcurrentlevel1 -Xtgc:parallel",
"""
jvm = getServerJvm(nodename,servername)
AdminConfig.modify(jvm, [[propertyname, value]])
But I'm met with this issue when i run the script
WASX7017E: Exception received while running file "/etc/was-scripts/administrateservertest.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "", line 14, in ?
NameError: maximumHeapsize
Any suggestions would be appreciated as I'm tearing my hair out trying to work this out
this was answered by a friend on face book
I think you might need to make two calls, one for each property you
want to set. e.g.
setJvmProperty(nodeName,serverName,'maximumHeapsize',2048)
For others looking for a more specific answer, try this:
AdminConfig.modify(jvmId,[['genericJvmArguments',arguments],["maximumHeapSize", str(1536)]])

WLST capture the output of state('ms1') to a variable

I need to capture the output of the below to a variable.
I know we can get to serverRuntime or domainRuntime() trees and get the state. But need to get the below working.
wls:/owb/serverConfig> state('Server1')
Current state of 'Server1' : RUNNING
I tried two ways:
wls:/owb/serverConfig> print state('Server1')
Current state of 'Server1' : RUNNING
None
wls:/owb/serverConfig> x=state('Server1')
Current state of 'Server1' : RUNNING
wls:/owb/serverConfig> print x
None
You have to use the getState() method of server runtime mbean.
You can obtain the server runtime mbean by navigating into wlst runtime tree or by using a lookup method.
Sample:
domainRuntime()
slrBean = cmo.lookupServerLifeCycleRuntime('Server1')
status = slrBean.getState()
print 'Status of Managed Server is '+status
See also Getting Runtime Information in WLST official documentation.
This same question was raised by Dianyuan Wang with me 2011.
Here is the steps to resolve your issue.
1. Capture the output of state command using redirect, stopRedirect command
2. Use the Python regular expression in search function to extract the desired server output.
Code snippet is here
fileName='/tmp/myserver_state.txt'
redirect(fileName)
state(server_nm,'Server')
stopRedirect()
f = open(fileName)
try:
for line in f.readlines():
if re.search('Current state',line):
status[server_nm]=line
except:
continue
Now you can apply desired logic after this block.
Cheers!!
HTH
Here is what I am using and is working like charm
cd("/ServerRuntimes/ms1")
state=cmo.getState()
print state