0

Issue: Unable to select an element id object using a stored variable.

Situation: I need to open a page, make a selection, store that selection in a variable card_id and next, find the element on the last page with the id pick_id and the stored variable, and click it. Hope I am being clear on this situation. If not, please just ask. I have tried to find the Selenium API documentation to handle this, nope.

Test Code:

def test_00_validation_test(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element_by_id("first_page").click()
        driver.find_element_by_id("make_pick").click()
        driver.find_element_by_xpath("(//input[@name='64'])[2]").click()
        driver.find_element_by_id("save_pick").click()
        self.assertEqual("Pick Was Saved", self.close_alert_and_get_its_text())
        card_id = driver.find_element_by_id("testingNum").get_attribute("value")
        driver.find_element_by_id("confirm_pick_page").click()
        driver.find_element_by_id("pick_id", card_id).click()
4
  • if you pass the id and selenium doesnt find it, its probably not in the html. if you are 100% its in the html it may be in an iframe. cant help you without knowing exactly what you too. Commented Oct 3, 2013 at 22:07
  • 1
    what do you mean by driver.find_element_by_id("pick_id", card_id) ? you cannot pass two arguments to this function. Please explain what you are trying to achieve in this function. Commented Oct 3, 2013 at 22:11
  • @user1411110 That is exactly right. I tried to cheat my way around it with the 2nd argument. Nope. I tried like this driver.find_element_by_id("pick_id").click(card_id) as well, nope. I know those aren't valid, but was hoping as I can not find another way to handle this scenario. Commented Oct 3, 2013 at 22:21
  • Also, for the 'what am I trying to achieve' question. Each pick I make is stored on the server, we hide that in the HTML as testingNum just for testing purposes, with the value it is being assigned. I get and store that value as card_id. So, when I go to the confirm_pick_page I can find it associated to the pick_id element. Commented Oct 3, 2013 at 22:25

1 Answer 1

1

Ok from your explanation i think you want to go the element pick_id then drill down and look for card_id and click on it. This could be done as:

card_id = driver.find_element_by_id("testingNum").get_attribute("value")
pick_id = driver.find_element_by_id("pick_id")
pick_id.find_element_by_id(card_id).click()

You can always find an element and then drill down that element using find_element_by.

Sign up to request clarification or add additional context in comments.

2 Comments

That will, and does, give NoSuchElementException. The card_id is a stored variable, and the usage of pick_id from your example is using it as you would driver., will not work. Just for the hell of it, I tried and it failed. Thanks for assisting though!
Is there another way to use the find_element_by_id function with 3 arguments, or another function that will take an element with the stored vale?

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.