2

I learning python recent, but I have some error.

environment python3 , chrome , webdriver(chrome)

from selenium import webdriver
import time
import random
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

driver = webdriver.Chrome("./chromedriver.exe") 

mobile_emulation = { "deviceName": 'Nexus 5' }
chrome_options = webdriver.ChromeOptions()


chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)


driver = webdriver.Remote(command_executor='https:xxx.com',desired_capabilities = chrome_options.to_capabilities())


driver.get("https:/xxx.com")

num = random.randint(11111111 , 99999999)

red = driver.find_element_by_class_name("***")
red.click()

numBox = driver.find_element_by_name("***")
numBox.send_keys(int(num))

reader = driver.find_element_by_id("***")
reader.send_keys("***")

comment = driver.find_element_by_css_selector(" ***")
comment.click()

and result error is here

Traceback (most recent call last):
  File "C:\python\pad\pad.py", line 16, in <module>
    driver = webdriver.Remote(command_executor='https:xxx.com',desired_capabilities = chrome_options.to_capabilities())
  File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 254, in start_session
    self.session_id = response['sessionId']
TypeError: string indices must be integers

I think the error because number of this code includes Decimal. but I cant find such number .

please give me advise

2
  • Is your web driver up-to-date? Commented Sep 17, 2018 at 5:55
  • I installed driver two days ago.so... Commented Sep 17, 2018 at 14:35

1 Answer 1

2

This error message...

Traceback (most recent call last):
  File "C:\python\pad\pad.py", line 16, in <module>
    driver = webdriver.Remote(command_executor='https:xxx.com',desired_capabilities = chrome_options.to_capabilities())
.
TypeError: string indices must be integers

...implies that there was a TypeError while invoking webdriver.Remote() method.

As per your code trials as you are using webdriver.Remote() with the argument command_executor perhaps you were trying to execute your tests in Selenium Grid Configuration.

As per the documentation documentation:

  • command_executor : remote_connection.RemoteConnection object used to execute commands.

    • Example:

      command_executor='http://127.0.0.1:4444/wd/hub'
      
    • The complete implementation:

      driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities = chrome_options.to_capabilities())
      

Note: Here we have considered that the Selenium Grid Hub and Selenium Grid Node are configured, up and running successfully with default configuration on the localhost.

Solution (Python 3.6)

Your effective code block will be:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions() 
chrome_options.add_argument("start-maximized")
chrome_options.add_argument('disable-infobars')
#driver = webdriver.Remote(command_executor='https:xxx.com', desired_capabilities = chrome_options.to_capabilities())
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities = chrome_options.to_capabilities())
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your comment . I dont have file in 127.0.0.1:4444/wd/hub . Is it OK? I refer this site sites.google.com/a/chromium.org/chromedriver/mobile-emulation python code.
ADDITION : I want to browser test in smartphone site.
@unowen Can you please take out some time to go through my answer once again? The argument command_executor is used when you use Selenium Grid configuration which involves a Hub and a Node. If you are not using Selenium Grid you shouldn't use the argument command_executor.
to clarify: command_executor is for remote webdriver. ... regardless if you are using a grid or a standalone selenium server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.