J
J
Just_Bruh2020-06-10 06:27:30
Python
Just_Bruh, 2020-06-10 06:27:30

How to access an element of a python array?

Thanks to

title = driver.find_elements_by_class_name('title')
in selenium I find the necessary elements, let's say there are four of them:
One
Two
Three
Four;
And I take them out:
for titles in title:
        print(titles.text)

Question: how to display a specific element, for example "Two"

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
goldsnitch, 2020-06-10
@Just_Bruh

Hello. I'm not familiar with Selenium specifically, but in Python you can refer to an element by index if, in fact, the title object supports indexing
First, try title[1].text
If it doesn't work, you can look in the documentation for a method that returns an indexed object, and if it doesn't exist, you can convert title, or its iterator, to a list with something like [i for i in title], or list(title)

D
Dmitry Entelis, 2014-07-14
@DmitriyEntelis

1. You cannot find out the full path to a file on a disk on a user's computer from php/js.
You can only get the file itself (when submitting the form) and its name.
*In principle, you can get the content of the file, but again, you will not do anything except send it to your server. ( www.html5rocks.com/ru/tutorials/file/dndfiles )
2. You cannot write a file from php/js to a user's computer at a specific path.
You can only initiate the download of the file by the user, and he will choose where to save it.

K
kis92, 2014-07-14
@kis92

phpclub.ru/detail/article/upload
as well as googling php file upload

U
uaSaint, 2014-07-14
@uaSaint

In general, I went a little different way ... The motive is to finish today, and they will pay me no more than $ 10 for it :)
1. I receive the file with the standard input type='file' and submit the form.
2. I accept the form and take the file name.
3. I use the function (just looking for a file):

if (!defined("__DLIB_FILEFIND_DEFINED")) 
  { 
  define('__DLIB_FILEFIND_DEFINED', TRUE); 

  function filefind ($basedirectory, $needle) 
     { 
     $handle=opendir($basedirectory); 
     while ($file = readdir($handle)) 
       { 
       if (($file == ".") || ($file == "..")) 
         continue; 

       if (is_dir($basedirectory . '/' . $file)) 
         { 
         $subDirResult = filefind($basedirectory . '/' . $file, $needle); 
         if ($subDirResult != "") 
           { 
           closedir($handle); 
           return $subDirResult; 
           } 
         }   //  if (is_dir($file)) 

       if (strcmp($file, $needle) == 0) 
         { 
         closedir($handle); 
         return $basedirectory . '/' . $needle; 
         } 

       }   // while ($file = readdir($handle)) 
     closedir($handle); 
     return ""; 
     }  //  function filefind 
  }

passing as a parameter '/' ( root directory ) and the resulting file name.
4. I display the result as a path.
PS The customer has windows... this is an adventure for me :( Maybe someone knows how to specify the root of the FS in windows? The
question of how to show the path that the user chose to save the file still remains...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question