0

Sorry i' want to get element of mobile chrome. Now i can get in body.but can't get class in body "tableID1" How to get element and text of "tableID1 - tableID10"

a busy cat

my code can get only body but can't get another element.

driver.find_element_by_id("body").get_attribute('innerHTML')

Pritam Maske
  • 2,670
  • 2
  • 22
  • 29
Mr.Water
  • 43
  • 4

2 Answers2

0

Jsut need to change the window size to show the id you want to see.

For Chromejust add before "webdriver.Chrome" init:

chrome_options.add_argument("--window-size=1920x1080")

For all browsers:

There is an official selenium python binding for that: http://selenium.googlecode.com/git/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.set_window_size

driver.set_window_size(1920, 1080)

or

driver.maximize_window()

or with javascript

driver.execute_script("window.resizeTo(1920,1080)")

Source : How do I resize the window in Chrome and Firefox when testing with Selenium?

0

Induce WebDriverWait and presence_of_all_elements_located() or visibility_of_all_elements_located() and use the below xpath. Try ele.text or ele.get_attribute('textContent')

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

elements=WebDriverWait(driver,20).until(EC.presence_of_all_elements_located((By.XPATH,"//div[@class='table_road_set'][starts-with(@id,'tableID')]")))
for ele in elements:
    print(ele.text)
    print(ele.get_attribute('textContent'))

OR

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

elements=WebDriverWait(driver,20).until(EC.visibility_of_all_elements_located((By.XPATH,"//div[@class='table_road_set'][starts-with(@id,'tableID')]")))
for ele in elements:
    print(ele.text)
    print(ele.get_attribute('textContent'))

You can use following Css Selector as well.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

elements=WebDriverWait(driver,20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,"div.table_road_set[id^='tableID']")))
for ele in elements:
    print(ele.text)
    print(ele.get_attribute('textContent'))
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • elements=WebDriverWait(driver,20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,"div.table_road_set[id^='tableID']"))) File "H:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: – Mr.Water Oct 14 '19 at 00:41
  • I believe element is not visible on the page.try presence_of_all_elements_located() – KunduK Oct 14 '19 at 08:01