Forum Discussion

Learner_Pranavi's avatar
Learner_Pranavi
Occasional Contributor
2 years ago

How to find background color of a cell in a table?

Hi guys,

I am unable to find the background color of a cell in the table. The table is on a chrome browser. It goes like Browser.Page.cell.

I am using python scripting. I need to check whether the cell is highlighted or not.

 

Any help is appreciated!

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Since you have not provided the full code, you will have to debug and step through your code to figure out the issue. 

     

    Type mismatch occurs when you assign a value to a variable that is not of its data type e.g. storing a number into a string variable.

  • Learner_Pranavi's avatar
    Learner_Pranavi
    Occasional Contributor

    Thanks rraghvani , I figured out the solution.

    My script goes like:

    page = Sys.Browser().Page("https://something.com/something..")

    style_21 = page.contentDocument.defaultView.getComputedStyle(Aliases.browser.WebPage.Cell_21 , "")
    Log.Message(style_21.backgroundColor)

     

    This worked for me and I got the result as:

    rgb(255,255,255)

     

    But suddenly while running tests, I am getting Type Mismatch error.

    The tests ran well previously. All of a sudden, I started getting this error.

    Please help!

    • Learner_Pranavi's avatar
      Learner_Pranavi
      Occasional Contributor
      At line style_21 = page.contentDocument.defaultView.getComputedStyle(Aliases.browser.WebPage.Cell_21 , "")

      Python Run time error, Type mismatch at this line.
  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I don't know if the method getComputedStyle accepts alias names. You also need to check that Cell_21 actually exists too.

    • Learner_Pranavi's avatar
      Learner_Pranavi
      Occasional Contributor
      Yeah, Cell_21 exists. It's actually a cell in a table.
      This worked fine for quite sometime. Suddenly the error began showing up.
  • jkrolczy's avatar
    jkrolczy
    Regular Contributor

    Provide some screenshot sof ObjectSpy for the cell when highlighted and not highlighted
    There will be an area from the ObjectSpy to dig deeper into for what you are looking for.

    I've done this for a table before.
    The info is there in ObjectSpy ... just have to find the correct spot for use in the code.